Permalink
Browse files

Add Edit Optional Graphs to clusterview as implemented by Jeffrey Len…

…sen. Also

rename the $config array in graph.php so it's not confused with $conf.
  • Loading branch information...
1 parent 0a17b30 commit 46e782e2ef5ce84341d4fef56d7d80d03233797e @vvuksan committed Mar 9, 2011
Showing with 146 additions and 61 deletions.
  1. +58 −49 ganglia-web/edit_optional_graphs.php
  2. +12 −12 ganglia-web/graph.php
  3. +76 −0 ganglia-web/templates/default/cluster_view.tpl
View
107 ganglia-web/edit_optional_graphs.php
@@ -7,17 +7,24 @@
require_once('./conf.php');
$hostname = $_GET['hostname'];
+$clustername = $_GET['clustername'];
+
+if ( $hostname != "" ) {
+ $filename = "/host_" . $hostname . ".json";
+} else if ( $clustername != "" ) {
+ $filename = "/cluster_" . $clustername . ".json";
+}
$default_reports = array("included_reports" => array(), "excluded_reports" => array());
$default_file = $conf['conf_dir'] . "/default.json";
if ( is_file($default_file) ) {
$default_reports = array_merge($default_reports,json_decode(file_get_contents($default_file), TRUE));
}
-$host_file = $conf['conf_dir'] . "/host_" . $hostname . ".json";
+$file = $conf['conf_dir'] . $filename;
$override_reports = array("included_reports" => array(), "excluded_reports" => array());
-if ( is_file($host_file) ) {
- $override_reports = array_merge($override_reports, json_decode(file_get_contents($host_file), TRUE));
+if ( is_file($file) ) {
+ $override_reports = array_merge($override_reports, json_decode(file_get_contents($file), TRUE));
}
if ( isset($_GET['action']) ) {
@@ -27,79 +34,79 @@
$report_name = str_replace("\"", "", $report_name);
switch ( $selection ) {
- case "included":
- # Check if report is already included by default
- if ( !in_array($report_name, $default_reports["included_reports"] ) ) {
- $reports["included_reports"][] = $report_name;
- }
- break;
- case "excluded":
- if ( !in_array($report_name, $default_reports["excluded_reports"] ) ) {
- $reports["excluded_reports"][] = $report_name;
- }
- break;
+ case "included":
+ # Check if report is already included by default
+ if ( !in_array($report_name, $default_reports["included_reports"] ) ) {
+ $reports["included_reports"][] = $report_name;
+ }
+ break;
+ case "excluded":
+ if ( !in_array($report_name, $default_reports["excluded_reports"] ) ) {
+ $reports["excluded_reports"][] = $report_name;
+ }
+ break;
}
}
if ( is_array($reports) ) {
$json = json_encode($reports);
- $host_file = $conf['conf_dir'] . "/host_" . $hostname . ".json";
- if ( file_put_contents($host_file, $json) === FALSE ) {
+ $file = $conf['conf_dir'] . $filename;
+ if ( file_put_contents($file, $json) === FALSE ) {
?>
- <div class="ui-widget">
- <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
- <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
- <strong>Alert:</strong> Can't write to file <?php print $host_file; ?>. Perhaps permissions are wrong.</p>
- </div>
- </div>
+ <div class="ui-widget">
+ <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
+ <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
+ <strong>Alert:</strong> Can't write to file <?php print $file; ?>. Perhaps permissions are wrong.</p>
+ </div>
+ </div>
<?php
} else {
?>
<div class="ui-widget">
- <div class="ui-state-default ui-corner-all" style="padding: 0 .7em;">
- <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
- Change written successfully.</p>
- </div>
- </div>
+ <div class="ui-state-default ui-corner-all" style="padding: 0 .7em;">
+ <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
+ Change written successfully.</p>
+ </div>
+ </div>
<?php
}
} else {
// Remove file if it already exists since there are no overrides
- if ( is_file($host_file) ) {
- if ( unlink($host_file) !== FALSE ) {
+ if ( is_file($file) ) {
+ if ( unlink($file) !== FALSE ) {
?>
<div class="ui-widget">
- <div class="ui-state-default ui-corner-all" style="padding: 0 .7em;">
- <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
- Change written successfully.</p>
- </div>
- </div>
+ <div class="ui-state-default ui-corner-all" style="padding: 0 .7em;">
+ <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
+ Change written successfully.</p>
+ </div>
+ </div>
<?php
} else {
?>
- <div class="ui-widget">
- <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
- <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
- <strong>Alert:</strong> Can't write to file <?php print $host_file; ?>. Perhaps permissions are wrong.</p>
- </div>
- </div>
+ <div class="ui-widget">
+ <div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
+ <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
+ <strong>Alert:</strong> Can't write to file <?php print $file; ?>. Perhaps permissions are wrong.</p>
+ </div>
+ </div>
<?php
}
} else {
?>
<div class="ui-widget">
- <div class="ui-state-default ui-corner-all" style="padding: 0 .7em;">
- <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
- Change written successfully.</p>
- </div>
- </div>
+ <div class="ui-state-default ui-corner-all" style="padding: 0 .7em;">
+ <p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
+ Change written successfully.</p>
+ </div>
+ </div>
<?php
- } // end of if ( is_file($host_file) ) {
+ } // end of if ( is_file($file) ) {
} // end of if ( is_array($reports)
@@ -109,6 +116,7 @@
<form id=edit_optional_reports_form>
<input type=hidden name=hostname value=<?php print $_GET['hostname']; ?>>
+<input type=hidden name=clustername value=<?php print $_GET['clustername']; ?>>
<input type=hidden name=action value=change>
<table border=1 width=90%>
<style>
@@ -118,7 +126,8 @@
</style>
<?php
-print "<h4>Hostname: " . $hostname . "</h4><br>";
+print "<h4>Hostname: " . $hostname . "</h4>";
+print "<h4>Clustername: " . $clustername . "</h4>";
?>
<?php
function create_radio_button($variable_name, $variable_value = "ignored") {
@@ -149,7 +158,7 @@ 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) )
+ if ( ! in_array($out[1] . "_report", $available_reports) )
$available_reports[] = $out[1] . "_report";
}
}
@@ -189,4 +198,4 @@ function create_radio_button($variable_name, $variable_value = "ignored") {
} // if ( isset($_GET['action') )
-?>
+?>
View
24 ganglia-web/graph.php
@@ -190,17 +190,17 @@
$graph_function = "graph_${graph}";
$graph_function( $rrdtool_graph ); // Pass by reference call, $rrdtool_graph modified inplace
} else if ( is_file( $json_report_file ) ) {
- $config = json_decode( file_get_contents( $json_report_file ), TRUE );
+ $graph_config = json_decode( file_get_contents( $json_report_file ), TRUE );
# We need to add hostname and clustername if it's not specified
- foreach ( $config['series'] as $index => $item ) {
- if ( ! isset($config['series'][$index]['hostname'])) {
- $config['series'][$index]['hostname'] = $raw_host;
- $config['series'][$index]['clustername'] = $clustername;
+ foreach ( $graph_config['series'] as $index => $item ) {
+ if ( ! isset($graph_config['series'][$index]['hostname'])) {
+ $graph_config['series'][$index]['hostname'] = $raw_host;
+ $graph_config['series'][$index]['clustername'] = $clustername;
}
}
- build_rrdtool_args_from_json ( $rrdtool_graph, $config );
+ build_rrdtool_args_from_json ( $rrdtool_graph, $graph_config );
}
// We must have a 'series' value, or this is all for naught
@@ -272,28 +272,28 @@
$report_definition_file = $ganglia_dir . "/graph.d/" . $report_name . ".json";
// Check whether report is defined in graph.d directory
if ( is_file($report_definition_file) ) {
- $config = json_decode(file_get_contents($report_definition_file), TRUE);
+ $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($config) ) {
- switch ( $config["report_type"] ) {
+ if ( isset($graph_config) ) {
+ switch ( $graph_config["report_type"] ) {
case "template":
- $target = str_replace("HOST_CLUSTER", $host_cluster, $config["graphite"]);
+ $target = str_replace("HOST_CLUSTER", $host_cluster, $graph_config["graphite"]);
break;
case "standard":
- $target = build_graphite_series( $config, $host_cluster );
+ $target = build_graphite_series( $graph_config, $host_cluster );
break;
default:
error_log("No valid report_type specified in the $report_name definition.");
break;
}
- $title = $config['title'];
+ $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);
View
76 ganglia-web/templates/default/cluster_view.tpl
@@ -1,3 +1,63 @@
+<script type="text/javascript">
+$(function() {
+ // Modified from http://jqueryui.com/demos/toggle/
+ //run the currently selected effect
+ function runEffect(id){
+ //most effect types need no options passed by default
+ var options = { };
+
+ options = { to: { width: 200,height: 60 } };
+
+ //run the effect
+ $("#"+id+"_div").toggle("blind",options,500);
+ };
+
+ //set effect from select menu value
+ $('.button').click(function(event) {
+ runEffect(event.target.id);
+ return false;
+ });
+
+ $(function() {
+ $( "#edit_optional_graphs" ).dialog({ autoOpen: false, minWidth: 550,
+ beforeClose: function(event, ui) { location.reload(true); } })
+ $( "#edit_optional_graphs_button" ).button();
+ $( "#save_optional_graphs_button" ).button();
+ $( "#close_edit_optional_graphs_link" ).button();
+ });
+
+ $("#edit_optional_graphs_button").click(function(event) {
+ $("#edit_optional_graphs").dialog('open');
+ $('#edit_optional_graphs_content').html('<img src="img/spinner.gif">');
+ $.get('edit_optional_graphs.php', "clustername={$cluster}", function(data) {
+ $('#edit_optional_graphs_content').html(data);
+ })
+ return false;
+ });
+
+ $("#save_optional_graphs_button").click(function(event) {
+ $.get('edit_optional_graphs.php', $("#edit_optional_reports_form").serialize(), function(data) {
+ $('#edit_optional_graphs_content').html(data);
+ });
+ return false;
+ });
+
+
+});
+</script>
+<style type="text/css">
+ .toggler { width: 500px; height: 200px; }
+ a.button { padding: .15em 1em; text-decoration: none; }
+ #effect { width: 240px; height: 135px; padding: 0.4em; position: relative; }
+ #effect h3 { margin: 0; padding: 0.4em; text-align: center; }
+</style>
+
+<div id="metric-actions-dialog" title="Metric Actions">
+ <div id="metric-actions-dialog-content">
+ Available Metric actions.
+ </div>
+</div>
+
<TABLE BORDER="0" CELLSPACING=5 WIDTH="100%">
<TR>
<TD CLASS=title COLSPAN="2">
@@ -22,6 +82,21 @@
{/if}
<hr>
</TD>
+</div>
+<style>
+#edit_optional_graphs_button {
+ font-size:12px;
+}
+#edit_optional_graphs_content {
+ padding: .4em 1em .4em 10px;
+}
+</style>
+<div id="edit_optional_graphs">
+ <div style="text-align: center;">
+ <button id='save_optional_graphs_button'>Save</button>
+ </div>
+ <div id="edit_optional_graphs_content">Empty</div>
+</div>
<TD ROWSPAN=2 ALIGN="CENTER" VALIGN=top>
<div id="optional_graphs">
@@ -31,6 +106,7 @@
<IMG BORDER=0 {$additional_cluster_img_html_args} ALT="{$cluster} {$graph.name}" SRC="./graph.php?{$graph.graph_args}&amp;g={$graph.name}_report&amp;z=medium"></A>
{/foreach}
</div>
+<button id="edit_optional_graphs_button">Edit Optional Graphs</button>
</TD>
</TR>

0 comments on commit 46e782e

Please sign in to comment.