From 4353d5ca72ae76af3fa54d3d27396e1c5d6ab9e9 Mon Sep 17 00:00:00 2001 From: Jochen Hein Date: Sun, 21 Jul 2013 14:17:39 +0200 Subject: [PATCH 1/4] We have lots of json-reports for clusters that we generate with a script. At the same time we recreate the cluster_.json file and add these reports to the included_reports. This works quite well, but means that there can't be local changes in the includes/excludes reports. So we've patched cluster_view.php, to look for reports matching cluster__.*_report.json (or php). If such a report exists, it is automatically added to the included_reports array and gets displayed. Since the change is very easy to port to the host_view (and we also have lot's of reports for hosts as well), that hunk is included too. Since this is a very visible change, review is welcome. If the changes are merged a description should be added to some documentation and possibly the ganglia book as well. --- cluster_view.php | 21 ++++++++++++++++++++- host_view.php | 23 ++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/cluster_view.php b/cluster_view.php index dc954ff4..0b9d4ae4 100644 --- a/cluster_view.php +++ b/cluster_view.php @@ -401,9 +401,28 @@ function get_cluster_optional_reports($conf, json_decode(file_get_contents($cluster_file), TRUE)); } + // Here we are looking for reports like cluster_.*_report.json + + if ($handle = opendir($conf['gweb_root'] . '/graph.d/')) { + $fs_reports = array(); + // If we are using RRDtool reports can be json or PHP suffixes + if ( $conf['graph_engine'] == "rrdtool" ) + $report_suffix = "php|json"; + else + $report_suffix = "json"; + + while (false !== ($file = readdir($handle))) { + if ( preg_match("/(cluster_" . $clustername . ".*)(_report)\.(" . $report_suffix .")/", $file, $out) ) { + $fs_reports["$out[1]"] = $out[1] . "_report"; + } + } + + closedir($handle); + } + # Merge arrays $reports["included_reports"] = - array_merge($default_reports["included_reports"],$override_reports["included_reports"]); + array_merge($default_reports["included_reports"],$override_reports["included_reports"],$fs_reports); $reports["excluded_reports"] = array_merge($default_reports["excluded_reports"],$override_reports["excluded_reports"]); diff --git a/host_view.php b/host_view.php index 3ee98ee9..2f3e42ef 100644 --- a/host_view.php +++ b/host_view.php @@ -88,11 +88,32 @@ function getOptionalReports($hostname, } } + // Here we are looking for reports like cluster_.*_report.json + + if ($handle = opendir($conf['gweb_root'] . '/graph.d/')) { + $fs_reports = array(); + // If we are using RRDtool reports can be json or PHP suffixes + if ( $conf['graph_engine'] == "rrdtool" ) + $report_suffix = "php|json"; + else + $report_suffix = "json"; + + while (false !== ($file = readdir($handle))) { + if ( preg_match("/(host_" . $hostname . ".*)(_report)\.(" . $report_suffix .")/", $file, $out) ) { + $fs_reports["$out[1]"] = $out[1] . "_report"; + } + } + + closedir($handle); + } + + // Merge arrays $reports["included_reports"] = array_merge( $default_reports["included_reports"], $cluster_override_reports["included_reports"], - $override_reports["included_reports"]); + $override_reports["included_reports"], + $fs_reports); $reports["excluded_reports"] = array_merge( $default_reports["excluded_reports"] , From 41c56e62d849b60dbbf5b50b6400ac5de904817b Mon Sep 17 00:00:00 2001 From: Jochen Hein Date: Mon, 22 Jul 2013 06:46:43 +0200 Subject: [PATCH 2/4] Fix comment after cut&paste The comment talks about cluster graphs, but here we are in host context. --- host_view.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host_view.php b/host_view.php index 2f3e42ef..74a94748 100644 --- a/host_view.php +++ b/host_view.php @@ -88,7 +88,7 @@ function getOptionalReports($hostname, } } - // Here we are looking for reports like cluster_.*_report.json + // Here we are looking for reports like host_.*_report.json if ($handle = opendir($conf['gweb_root'] . '/graph.d/')) { $fs_reports = array(); From 09f55d3226c1f6da06b71f134ade06f0a8024a00 Mon Sep 17 00:00:00 2001 From: Jochen Hein Date: Wed, 14 Aug 2013 22:03:42 +0200 Subject: [PATCH 3/4] hide automatic graphs from view in edit_optional_graphs and metric drop-down list In the cluster view we can select the metric that is displayed for each host. Until now all reports/metrics are displayed in the dropdown-list "Metric". In the "Edit Optional Graphs" we had all reports for cluster and host. In our system we have dozens of reports for our clusters (but only some relevant for each cluster) and hundreds of different reports for hosts (and again only some relevant for each host). The earlier patches added the reports automagically to clusters and hosts respectively, so there is no need to add these reports in the edit_optional_graphs.php and the metric drop-down list in the cluster_view. For both lists we exclude the (cluster|host)_*_report.json from view, because they are always included as we need it. --- edit_optional_graphs.php | 6 ++++-- header.php | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/edit_optional_graphs.php b/edit_optional_graphs.php index 95e3ea3d..a4655727 100644 --- a/edit_optional_graphs.php +++ b/edit_optional_graphs.php @@ -185,8 +185,10 @@ function create_radio_button($variable_name, $variable_value = "ignored") { while (false !== ($file = readdir($handle))) { if ( preg_match("/(.*)(_report)\.(" . $report_suffix .")/", $file, $out) ) { - if ( ! in_array($out[1] . "_report", $available_reports) ) - $available_reports[] = $out[1] . "_report"; + if ( ! preg_match("/((cluster|host)_.*)(_report)/", $file) ) { + if ( ! in_array($out[1] . "_report", $available_reports) ) + $available_reports[] = $out[1] . "_report"; + } } } diff --git a/header.php b/header.php index 046f4762..be67d45a 100755 --- a/header.php +++ b/header.php @@ -423,8 +423,10 @@ function make_node_menu($self, while (false !== ($file = readdir($handle))) { if ( preg_match("/(.*)(_report)\.(" . $report_suffix .")/", $file, $out) ) { - if ( ! in_array($out[1] . "_report", $context_metrics) ) - $context_metrics[] = $out[1] . "_report"; + if ( ! preg_match("/((cluster|host)_.*)(_report)/", $file) ) { + if ( ! in_array($out[1] . "_report", $context_metrics) ) + $context_metrics[] = $out[1] . "_report"; + } } } From 54fed0efad229c43ab9c18f5174163b31e31dc83 Mon Sep 17 00:00:00 2001 From: Jochen Hein Date: Fri, 16 Aug 2013 06:51:39 +0200 Subject: [PATCH 4/4] hide selected metrics from drop down menu We have hundreds of local metrics that are only useful for a single host. Currently all of these metrics are added to the drop down menu in the cluster view. This patch defines the configuration option 'cluster_hide_metrics_from_menu', a regular expression. All metrics matching this regular expression are hidden from the drop down menu. --- conf_default.php.in | 6 ++++++ header.php | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/conf_default.php.in b/conf_default.php.in index 0d83c1c2..1da0f578 100644 --- a/conf_default.php.in +++ b/conf_default.php.in @@ -188,6 +188,12 @@ $conf['strip_domainname'] = false; # $conf['cluster_hide_down_hosts'] = false; +# +# hide special metrics from drop-down list in cluster view, +# all metrics matching the regular expression are hidden +# +$conf['cluster_hide_metrics_from_menu'] = '^(cluster|host)_.*_report'; + # # Optional summary graphs # This function is deprecated. Please configure included reports diff --git a/header.php b/header.php index be67d45a..4df17a35 100755 --- a/header.php +++ b/header.php @@ -394,7 +394,9 @@ function make_node_menu($self, if (count($metrics)) { foreach ($metrics as $firsthost => $bar) { foreach ($metrics[$firsthost] as $m => $foo) - $context_metrics[$m] = $m; + if ( ! preg_match("/" . $conf['cluster_hide_metrics_from_menu'] . "/", $m) ) { + $context_metrics[$m] = $m; + } } foreach ($reports as $r => $foo) $context_metrics[] = $r; @@ -423,7 +425,7 @@ function make_node_menu($self, while (false !== ($file = readdir($handle))) { if ( preg_match("/(.*)(_report)\.(" . $report_suffix .")/", $file, $out) ) { - if ( ! preg_match("/((cluster|host)_.*)(_report)/", $file) ) { + if ( ! preg_match("/" . $conf['cluster_hide_metrics_from_menu'] . "/", $file) ) { if ( ! in_array($out[1] . "_report", $context_metrics) ) $context_metrics[] = $out[1] . "_report"; }