public function addMetric($metric, $alias = null, $options = null, $functions = array()) { parent::addMetric($metric); $i = count($this->metrics) - 1; $this->metrics[$i]["alias"] = $alias; $this->metrics[$i]["options"] = $options; $this->metrics[$i]["functions"] = $functions; }
/** * @param array $graph_config * @return string */ private function getGraphiteDashboardHTML($graph_config) { $graph_time = $graph_config['graph_time']; $show_deploys = $graph_config['show_deploys']; $width = $graph_config['width']; $height = $graph_config['height']; $title = isset($graph_config['title']) ? $graph_config['title'] : ''; $show_legend = isset($graph_config['show_legend']) ? $graph_config['show_legend'] : false; $stacked = isset($graph_config['stacked']) ? $graph_config['stacked'] : false; $line_mode = isset($graph_config['line_mode']) ? $graph_config['line_mode'] : false; $area_mode = isset($graph_config['area_mode']) ? $graph_config['area_mode'] : false; $vtitle = isset($graph_config['vtitle']) ? $graph_config['vtitle'] : false; $y_max = isset($graph_config['y_max']) ? $graph_config['y_max'] : false; $hide_axes = isset($graph_config['hide_axes']) ? $graph_config['hide_axes'] : false; $hide_grid = isset($graph_config['hide_grid']) ? $graph_config['hide_grid'] : false; $is_black = isset($graph_config['is_black']) ? $graph_config['is_black'] : isset($_GET['black']); $is_pie_chart = isset($graph_config['is_pie_chart']) ? $graph_config['is_pie_chart'] : false; $show_html_legend = isset($graph_config['show_html_legend']) ? $graph_config['show_html_legend'] : false; $show_copy_url = isset($graph_config['show_copy_url']) ? $graph_config['show_copy_url'] : true; $numerator_metrics = isset($graph_config['numerator_metrics']) ? $graph_config['numerator_metrics'] : array(); $denominator_metrics = isset($graph_config['denominator_metrics']) ? $graph_config['denominator_metrics'] : array(); $ratio_suffix = isset($graph_config['ratio_suffix']) ? $graph_config['ratio_suffix'] : null; $legend_keys = isset($graph_config['legend_keys']) ? $graph_config['legend_keys'] : array(); $is_ajax = isset($graph_config['is_ajax']) ? $graph_config['is_ajax'] : false; $xaxis_type = isset($graph_config['xaxis_type']) ? $graph_config['xaxis_type'] : 'date'; $yaxis_type = isset($graph_config['yaxis_type']) ? $graph_config['yaxis_type'] : null; $until_time = isset($graph_config['until']) ? $graph_config['until'] : null; if ($is_pie_chart) { // deploys don't work with pie charts $graph_config['show_deploys'] = false; } $metrics = $this->getMetrics($graph_config); $colors = $this->getColors($graph_config); $g = new Graph_Graphite($graph_time, $until_time); $g->setTitle($title); $g->setVTitle($vtitle); if ($line_mode) { $g->setLineMode($line_mode); } if ($area_mode) { $g->setAreaMode($area_mode); } if ($is_pie_chart) { $g->displayPieChart(true); } if ($is_black) { $g->setBgColor('black'); $g->setFgColor('white'); } for ($i = 0; $i < count($metrics); $i++) { $metric = $metrics[$i]; $color = null; if (isset($colors[$i])) { if (isset(self::$NAMED_COLORS[$colors[$i]])) { $color = '#' . self::$NAMED_COLORS[$colors[$i]]; } elseif (preg_match('/^[a-fA-F0-9]{6}$/', $colors[$i], $matches)) { $color = '#' . $colors[$i]; } } $g->addMetric($metric, $color); } // Show deploys on low grain if (isset($graph_config['show_deploys'])) { $show_deploys_graph = $graph_config['show_deploys']; } else { $show_deploys_graph = $show_deploys; } if ($show_deploys_graph && ($graph_time == "1h" || $graph_time == "2h" || $graph_time == "4h")) { $g->showDeploys(true); } else { $g->showDeploys(false); } $g->hideLegend(!$show_legend); $g->displayStacked($stacked); $g->hideGrid($hide_grid); $g->hideAxes($hide_axes); $g->useHtmlLegend($show_html_legend); $g->showCopyUrl($show_copy_url); $g->setLegendKeys($legend_keys); $g->isAjax($is_ajax); $g->setXaxisType($xaxis_type); $g->setYaxisType($yaxis_type); if ($y_max) { $g->setYMax($y_max); } if (array_key_exists('y_min', $graph_config)) { $g->setYMin($graph_config['y_min']); } if ($numerator_metrics && $denominator_metrics) { $g->setRatioMetrics($numerator_metrics, $denominator_metrics); $g->setRatioSuffix($ratio_suffix); } $html_legend = $this->getLegendHtml($metrics, $colors, $graph_config); return $g->getDashboardHTML($width, $height, $html_legend); }