/** * @return GraphFactory */ public static function getInstance() { if (!isset(self::$instance)) { self::$instance = new GraphFactory(); } return self::$instance; }
/** * @param bool $hide_deploys * @return string */ public static function buildShowDeploysControl($hide_deploys, $itemize = true) { $show_deploys = !$hide_deploys; $html = "<span style='margin-left: 5px;'>" . self::buildControl(self::buildCheckbox('hide_deploys', 'Hide All Deploys', $hide_deploys)); if ($itemize && $show_deploys) { $deploy_html = "Deploys hidden: "; foreach (DeployConstants::$deploys as $deploy_name => $deploy) { $checked = true; if (!GraphFactory::isHiddenDeployType($deploy_name)) { $checked = false; } $deploy_html .= "<span style=\"color: {$deploy['color']}; margin-right: 5px;\">" . self::buildCheckbox($deploy_name, $deploy['title'], $checked) . "</span>\n"; } $html .= self::buildControl($deploy_html); } $html .= "<span style='color: #dddddd'>Historical Average</span>"; $html .= "</span>"; return $html; }
public function getDashboardHTML($width, $height, $add_integral = true) { $id = 'graphite-pie-' . str_replace('.', '', microtime(true)); $legend_width = $width - 20; $graph_height = $height + 20; $show_labels = $this->show_labels ? 'true' : 'false'; $show_legend = $this->show_legend ? 'true' : 'false'; $sort_legend = $this->sort_legend ? 'true' : 'false'; if ($this->is_ajax) { $time = GraphiteHelper::getTimeParam($this->time); $metrics = json_encode($this->metrics); $legend_keys = json_encode($this->legend_keys); $threshold = isset($this->threshold) ? $this->threshold : 'null'; $formatted_colors = array(); foreach ((array) $this->colors as $color_description) { $color = GraphFactory::getHexColorValue($color_description); $formatted_colors[] = "#{$color}"; } $formatted_use_average = $this->use_average ? 'true' : 'false'; $colors = json_encode($formatted_colors); return <<<EOF <div class='flotGraph graphite-pie' data-time='{$time}' data-metrics='{$metrics}' data-legend-keys='{$legend_keys}' data-colors='{$colors}' data-show-labels='{$show_labels}' data-show-legend='{$show_legend}' data-sort-legend='{$sort_legend}' data-threshold='{$threshold}' data-use-average='{$formatted_use_average}' > <p class='html_title' style='width: {$legend_width}px;'>{$this->title}</p> <div class='flot-container' id='{$id}' style='height: {$graph_height}px; width: {$width}px;'></div> </div> EOF; } else { $targets = array(); foreach ($this->metrics as $metric) { $targets[] = $add_integral ? "integral({$metric})" : $metric; } $data = GraphiteHelper::fetchSplitRenderDataMultipleTargets($targets, $this->time); $json_data_values = array(); foreach ($data as $index => $split_data) { if ($add_integral) { $method = count($this->legend_keys) > $index ? $this->legend_keys[$index] : $this->metrics[$index]; } else { $header = $split_data[0]; list($method) = explode(',', $header); } if (count($split_data) > 1) { $data_points = explode(',', $split_data[1]); if ($add_integral) { $total = GraphiteHelper::getMaxValue($data_points); } else { $total = GraphiteHelper::getTotal($data_points); } $json_data_values[] = '{label:"' . $method . '", data:' . $total . '}'; } } $json_data = '[' . implode(',', $json_data_values) . ']'; $threshold_setting = isset($this->threshold) ? "threshold: {$this->threshold}," : ''; $stroke_setting = isset($this->bgColor) ? "stroke: { color: '{$this->bgColor}' }," : ''; $formatted_colors = array(); if ($this->colors) { foreach ($this->colors as $color_description) { $color = GraphFactory::getHexColorValue($color_description); $formatted_colors[] = "'#{$color}'"; } $colors = 'colors: [' . implode(',', $formatted_colors) . '],'; } else { $colors = ''; } if ($this->show_legend && !$this->show_labels) { $label_formatter = <<<EOF labelFormatter: function(label,data) { return label + ' (' + (Math.round(data.percent*100)/100) + '%)'; }, EOF; } else { $label_formatter = ""; } return <<<EOF <div class='flotGraph'> <p class='html_title' style='width: {$legend_width}px;'>{$this->title}</p> <div id='{$id}' style='height: {$graph_height}px; width: {$width}px;'></div> <script type="text/javascript"> var data = {$json_data}; jQuery.plot(jQuery("#{$id}"), data, { {$colors} series: { pie: { {$stroke_setting} show: true, label: { show: {$show_labels} }, combine: { {$threshold_setting} color: '#999' } } }, legend: { {$label_formatter} show: {$show_legend} }, grid: { hoverable: true } }); </script> </div> EOF; } }
public function showDeploys($show = true) { if ($show) { foreach (array_reverse(DeployConstants::$deploys) as $deploy_name => $deploy) { if (!GraphFactory::isHiddenDeployType($deploy_name)) { $target = "alias(drawAsInfinite({$deploy['target']}), 'Deploy: {$deploy['title']}')"; $this->addMetric($target, $deploy['color'], true); } } } }
<div class="notice">Some timeframes may cause <strong>Ganglia</strong>-generated graphs to be missing some of the most recent data, which can appear as if 1/2 of the server pool suddenly dropped out. This is a known issue. Balance this information with other graphs when determining if you just broke something!</div> <?php } ?> <?php if ($has_jenkins && $time != '1h') { ?> <div class="notice"><strong>Jenkins</strong> can only display graphs in three time intervals: <em>one-hour, one-day </em>and<em> one-week.</em> Jenkins graphs displayed here are using the time interval closest to the one you selected.</div> <?php } ?> <?php if (isset($html_for_header)) { print $html_for_header; } ?> <div id="frame"> <?php echo GraphFactory::getInstance()->getDashboardSectionsHTML($graphs, $time, $show_deploys); ?> <?php if (isset($additional_html)) { print $additional_html; } ?> </div>