Пример #1
0
function build_graphite_url($rrd_graphite_link, $rrd_dir, $conf, $clustername, $host, $size, $height, $width, $graph_config, $context, $metric_name, $cs, $ce, $start, $end, $min, $max, $title, $range)
{
    // Check whether the link exists from Ganglia RRD tree to the graphite
    // storage/rrd_dir area
    if (!is_link($rrd_graphite_link)) {
        // Does the directory exist for the cluster. If not create it
        if (!is_dir($conf['graphite_rrd_dir'] . "/" . str_replace(" ", "_", $clustername))) {
            mkdir($conf['graphite_rrd_dir'] . "/" . str_replace(" ", "_", $clustername));
        }
        symlink($rrd_dir, str_replace(" ", "_", $rrd_graphite_link));
    }
    // Generate host cluster string
    if (isset($clustername)) {
        $host_cluster = str_replace(" ", "_", $clustername) . "." . $host;
    } else {
        $host_cluster = $host;
    }
    $height += 70;
    if ($size == "small") {
        $width += 20;
    }
    // If graph_config is already set we can use it immediately
    if (isset($graph_config)) {
        $target = build_graphite_series($context, $graph_config, "");
    } else {
        if (isset($_GET['g'])) {
            // if it's a report increase the height for additional 30 pixels
            $height += 40;
            $report_name = sanitize($_GET['g']);
            $report_definition_file = $conf['gweb_root'] . "/graph.d/" . $report_name . ".json";
            // Check whether report is defined in graph.d directory
            if (is_file($report_definition_file)) {
                $graph_config = json_decode(file_get_contents($report_definition_file), TRUE);
            } else {
                error_log("There is JSON config file specifying {$report_name}.");
                exit(1);
            }
            if (isset($graph_config)) {
                switch ($graph_config["report_type"]) {
                    case "template":
                        $target = str_replace("HOST_CLUSTER", $conf['graphite_prefix'] . $host_cluster, $graph_config["graphite"]);
                        break;
                    case "standard":
                        $target = build_graphite_series($context, $graph_config, $conf['graphite_prefix'] . $host_cluster);
                        break;
                    default:
                        error_log("No valid report_type specified in the " . $report_name . " definition.");
                        break;
                }
                $title = $graph_config['title'];
            } else {
                error_log("Configuration file to {$report_name} exists; " . "however, it doesn't appear it's a valid JSON file");
                exit(1);
            }
        } else {
            // It's a simple metric graph
            $vlabel = isset($_GET["vl"]) ? sanitize($_GET["vl"]) : NULL;
            $target = "target=" . $conf['graphite_prefix'] . "{$host_cluster}.{$metric_name}.sum&hideLegend=true&vtitle=" . urlencode($vlabel) . "&areaMode=all&colorList=" . $conf['default_metric_color'];
            $title = " ";
        }
    }
    if ($cs) {
        $start = date("H:i_Ymd", strtotime($cs));
    }
    if ($ce) {
        $end = date("H:i_Ymd", strtotime($ce));
    }
    if ($max == 0) {
        $max = "";
    }
    $graphite_url = $conf['graphite_url_base'] . "?width={$width}&height={$height}&" . $target . "&from=" . $start . "&until=" . $end . "&yMin=" . $min . "&yMax=" . $max . "&bgcolor=FFFFFF&fgcolor=000000&title=" . urlencode($title . " last " . $range);
    return $graphite_url;
}
Пример #2
0
 // Check whether report is defined in graph.d directory
 if ( is_file($report_definition_file) ) {
   $graph_config = json_decode(file_get_contents($report_definition_file), TRUE);
 } else {
   error_log("There is JSON config file specifying $report_name.");
   exit(1);
 }
 
 if ( isset($graph_config) ) {
   switch ( $graph_config["report_type"] ) {
     case "template":
       $target = str_replace("HOST_CLUSTER", $host_cluster, $graph_config["graphite"]);
       break;
 
     case "standard":
       $target = build_graphite_series( $graph_config, $host_cluster );
       break;
 
     default:
       error_log("No valid report_type specified in the $report_name definition.");
       break;
   }
 
   $title = $graph_config['title'];
 } else {
   error_log("Configuration file to $report_name exists however it doesn't appear it's a valid JSON file");
   exit(1);
 }
   } else {
 // It's a simple metric graph
 $target = "target=$host_cluster.$metric_name.sum&hideLegend=true&vtitle=" . urlencode($vlabel) . "&areaMode=all";
Пример #3
0
     $report_name = sanitize($_GET['g']);
     $report_definition_file = $conf['gweb_root'] . "/graph.d/" . $report_name . ".json";
     // Check whether report is defined in graph.d directory
     if (is_file($report_definition_file)) {
         $graph_config = json_decode(file_get_contents($report_definition_file), TRUE);
     } else {
         error_log("There is JSON config file specifying {$report_name}.");
         exit(1);
     }
     if (isset($graph_config)) {
         switch ($graph_config["report_type"]) {
             case "template":
                 $target = str_replace("HOST_CLUSTER", $conf['graphite_prefix'] . $host_cluster, $graph_config["graphite"]);
                 break;
             case "standard":
                 $target = build_graphite_series($graph_config, $conf['graphite_prefix'] . $host_cluster);
                 break;
             default:
                 error_log("No valid report_type specified in the " . $report_name . " definition.");
                 break;
         }
         $title = $graph_config['title'];
     } else {
         error_log("Configuration file to {$report_name} exists however it doesn't appear it's a valid JSON file");
         exit(1);
     }
 } else {
     // It's a simple metric graph
     $target = "target=" . $conf['graphite_prefix'] . "{$host_cluster}.{$metric_name}.sum&hideLegend=true&vtitle=" . urlencode($vlabel) . "&areaMode=all&colorList=" . $conf['default_metric_color'];
     $title = " ";
 }