public function getDashboardHTML($width, $height, $id)
    {
        $time = GraphiteHelper::getTimeParam($this->time);
        $max = json_encode(100);
        $numerator = json_encode($this->numerator_metrics);
        $denominator = json_encode($this->denominator_metrics);
        $legend_keys = json_encode($this->legend_keys);
        if ($this->percentage_type == self::NUMBER_PERCENTAGE) {
            $interior_html = <<<EOF
                <span class="col_left">
                <span class="value_whole">--</span>
                </span><span class="col_right">
                <span
                    class="value_point">.</span><span
                    class="value_decimal">--</span><span
                    class="value_symbol">%</span>
                <span class="unit">{$this->title}</span>
                </span>
EOF;
        } else {
            $interior_html = '';
        }
        return <<<EOF
            <span id="{$id}" class="graphiteGraph {$this->percentage_type} stat"
                  style="width:{$width}px; height: {$height}px;"
                  data-time="{$time}"
                  data-title='{$this->title}'
                  data-max='{$max}'
                  data-numerator='{$numerator}'
                  data-denominator='{$denominator}'
                  data-legend-keys='{$legend_keys}'
                  >
                  {$interior_html}
            </span>
EOF;
    }
Example #2
0
<?php

require_once '../phplib/Dashboard.php';
$from = isset($_GET['from']) ? $_GET['from'] : '';
$max = isset($_GET['max']) ? (double) $_GET['max'] : null;
$numerators = isset($_GET['n']) ? (array) $_GET['n'] : array();
$denominators = isset($_GET['d']) ? (array) $_GET['d'] : array();
$graphite_results = GraphiteHelper::fetchKeyedSplitRenderDataMultipleTargets(array_merge($numerators, $denominators), $from);
$details = array();
$values = array();
$current_denominator = $denominators[0];
foreach ($numerators as $index => $numerator) {
    $denominator = isset($denominators[$index]) ? $denominators[$index] : $current_denominator;
    $numerator_value = isset($graphite_results[$numerator]) ? GraphiteHelper::getTotal($graphite_results[$numerator]) / count($graphite_results[$numerator]) : 0.0;
    $denominator_value = isset($graphite_results[$denominator]) ? GraphiteHelper::getTotal($graphite_results[$denominator]) / count($graphite_results[$denominator]) : 0.0;
    $value = $denominator_value != 0.0 ? $numerator_value / $denominator_value * 100 : 0.0;
    if ($max != null) {
        $value = min($value, $max);
    }
    $values[] = $value;
    $details[] = array($numerator_value, $denominator_value);
}
$result = array(array('measures' => $values, 'details' => $details, 'ranges' => array(100)));
header("Content-type: application/json");
print json_encode($result);
Example #3
0
    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;
        }
    }
Example #4
0
 /**
  * @param array $methods
  * @return array
  */
 private static function buildParameterGraphs($methods)
 {
     $performance_graphs = array();
     foreach ($methods as $method) {
         $title = str_replace('.', '/', $method) . '.php';
         $get_params = GraphiteHelper::fetchChildMetrics("stats.page_params.{$method}.get.*");
         $get_metrics = array();
         foreach ($get_params as $get_param) {
             $get_metrics[] = "stats.page_params.{$method}.get.{$get_param}";
         }
         $post_params = GraphiteHelper::fetchChildMetrics("stats.page_params.{$method}.post.*");
         $post_metrics = array();
         foreach ($post_params as $post_param) {
             $post_metrics[] = "stats.page_params.{$method}.post.{$post_param}";
         }
         $performance_graphs[] = TimingUtils::buildGraphitePie("{$title}<br/>GET Params", $get_metrics, $get_params, GraphConstants::FOUR_GRAPH_WIDTH);
         $performance_graphs[] = TimingUtils::buildGraphite("{$title}<br/>GET Params", $get_metrics, $get_params, GraphConstants::FOUR_GRAPH_WIDTH);
         $performance_graphs[] = TimingUtils::buildGraphitePie("{$title}<br/>POST Params", $post_metrics, $post_params, GraphConstants::FOUR_GRAPH_WIDTH);
         $performance_graphs[] = TimingUtils::buildGraphite("{$title}<br/>POST Params", $post_metrics, $post_params, GraphConstants::FOUR_GRAPH_WIDTH);
     }
     return $performance_graphs;
 }
Example #5
0
<?php

require_once '../phplib/Dashboard.php';
$from = isset($_GET['from']) ? $_GET['from'] : '';
$targets = isset($_GET['t']) ? (array) $_GET['t'] : array();
$graphite_results = GraphiteHelper::fetchKeyedSplitRenderDataMultipleTargets($targets, $from);
$totals = array();
foreach ($targets as $target) {
    $value = isset($graphite_results[$target]) ? GraphiteHelper::getTotal($graphite_results[$target]) : 0.0;
    $totals[$target] = $value;
}
$result = array('totals' => $totals);
header("Content-type: application/json");
print json_encode($result);
Example #6
0
    private function getRatioHtml()
    {
        $time = GraphiteHelper::getTimeParam($this->time);
        $numerator = json_encode($this->numerator_metrics);
        $denominator = json_encode($this->denominator_metrics);
        $ratio_suffix = $this->ratio_suffix ? " {$this->ratio_suffix}" : '';
        if ($this->numerator_metrics && $this->denominator_metrics) {
            return <<<EOF
                <span class="legend-graphite-percentage"
                      data-time="{$time}"
                      data-numerator='{$numerator}'
                      data-denominator='{$denominator}'
                      >
                    (<span class="value_whole">-</span><span class="value_point">.</span><span class="value_decimal">-</span>%{$ratio_suffix})
                </span>
EOF;
        } else {
            return '';
        }
    }
Example #7
0
 /**
  * @param string $metric_parent
  * @param array $methods_to_filter
  * @return array
  */
 public static function getAllMethods($metric_parent, $methods_to_filter)
 {
     $methods = GraphiteHelper::fetchChildMetrics("stats.timers.{$metric_parent}.");
     $valid_methods = array();
     foreach ($methods as $method) {
         if (!in_array($method, $methods_to_filter)) {
             $valid_methods[] = $method;
         }
     }
     return $valid_methods;
 }