Skip to content

Commit

Permalink
Extend show events to support the host view
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Piela committed Jan 18, 2012
1 parent 9b5201d commit a7f8064
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 149 deletions.
100 changes: 100 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1446,4 +1446,104 @@ function retrieve_metrics_cache () {

} // end of function get_metrics_cache () {

function getHostOverViewData($hostname,
$metrics,
$cluster,
$hosts_up,
$hosts_down,
$always_timestamp,
$always_constant,
$data) {
$data->assign("extra", template("host_extra.tpl"));

$data->assign("host", $hostname);
$data->assign("node_image", node_image($metrics));

if ($hosts_up)
$data->assign("node_msg", "This host is up and running.");
else
$data->assign("node_msg", "This host is down.");

# No reason to go on if this node is down.
if ($hosts_down)
return;

foreach ($metrics as $name => $v) {
if ($v['TYPE'] == "string" or $v['TYPE']=="timestamp" or
(isset($always_timestamp[$name]) and $always_timestamp[$name])) {
$s_metrics[$name] = $v;
} elseif ($v['SLOPE'] == "zero" or
(isset($always_constant[$name]) and $always_constant[$name])) {
$c_metrics[$name] = $v;
}
}

# in case this is not defined, set to LOCALTIME so uptime will be 0 in the display
$boottime = null;
if (isset($metrics['boottime']['VAL']))
$boottime = $metrics['boottime']['VAL'];
else
$boottime = $cluster['LOCALTIME'];

# Add the uptime metric for this host. Cannot be done in ganglia.php,
# since it requires a fully-parsed XML tree. The classic contructor problem.
$s_metrics['uptime']['TYPE'] = "string";
$s_metrics['uptime']['VAL'] = uptime($cluster['LOCALTIME'] - $boottime);
$s_metrics['uptime']['TITLE'] = "Uptime";

# Add the gmond started timestamps & last reported time (in uptime format) from
# the HOST tag:
$s_metrics['gmond_started']['TYPE'] = "timestamp";
$s_metrics['gmond_started']['VAL'] = $hosts_up['GMOND_STARTED'];
$s_metrics['gmond_started']['TITLE'] = "Gmond Started";
$s_metrics['last_reported']['TYPE'] = "string";
$s_metrics['last_reported']['VAL'] = uptime($cluster['LOCALTIME'] - $hosts_up['REPORTED']);
$s_metrics['last_reported']['TITLE'] = "Last Reported";

$s_metrics['ip_address']['TITLE'] = "IP Address";
$s_metrics['ip_address']['VAL'] = $hosts_up['IP'];
$s_metrics['ip_address']['TYPE'] = "string";
$s_metrics['location']['TITLE'] = "Location";
$s_metrics['location']['VAL'] = $hosts_up['LOCATION'];
$s_metrics['location']['TYPE'] = "string";

# String metrics
if (is_array($s_metrics)) {
$s_metrics_data = array();
ksort($s_metrics);
foreach ($s_metrics as $name => $v) {
# RFM - If units aren't defined for metric, make it be the empty string
! array_key_exists('UNITS', $v) and $v['UNITS'] = "";
if (isset($v['TITLE'])) {
$s_metrics_data[$name]["name"] = $v['TITLE'];
} else {
$s_metrics_data[$name]["name"] = $name;
}
if ($v['TYPE']=="timestamp" or
(isset($always_timestamp[$name]) and $always_timestamp[$name])) {
$s_metrics_data[$name]["value"] = date("r", $v['VAL']);
} else {
$s_metrics_data[$name]["value"] = $v['VAL'] . " " . $v['UNITS'];
}
}
}
$data->assign("s_metrics_data", $s_metrics_data);

# Constant metrics.
$c_metrics_data = null;
if (isset($c_metrics) and is_array($c_metrics)) {
$c_metrics_data = array();
ksort($c_metrics);
foreach ($c_metrics as $name => $v) {
if (isset($v['TITLE'])) {
$c_metrics_data[$name]["name"] = $v['TITLE'];
} else {
$c_metrics_data[$name]["name"] = $name;
}
$c_metrics_data[$name]["value"] = "$v[VAL] $v[UNITS]";
}
}
$data->assign("c_metrics_data", $c_metrics_data);
}

?>
2 changes: 1 addition & 1 deletion header.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@
$data->assign('view_name', $user['viewname']);

$additional_buttons = "";
if ($context == "views" || $context == "decompose_graph") {
if ($context == 'views' || $context == 'decompose_graph' || $context == 'host') {
$additional_buttons = '<input title="Hide/Show Events" type="checkbox" id="show_all_events" onclick="showAllEvents(this.checked)"/><label for="show_all_events">Hide/Show Events</label>';
}
$data->assign('additional_buttons', $additional_buttons);
Expand Down
29 changes: 29 additions & 0 deletions host_overview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
include_once "./eval_conf.php";
include_once "./functions.php";
include_once "./get_context.php";
include_once "./ganglia.php";
include_once "./get_ganglia.php";
include_once "./dwoo/dwooAutoload.php";

try {
$dwoo = new Dwoo($conf['dwoo_compiled_dir'], $conf['dwoo_cache_dir']);
} catch (Exception $e) {
print "<H4>There was an error initializing the Dwoo PHP Templating Engine: " .
$e->getMessage() .
"<br><br>The compile directory should be owned and writable by the apache user.</H4>";
exit;
}

$tpl = new Dwoo_Template_File( template("host_overview.tpl") );
$data = new Dwoo_Data();
getHostOverViewData($hostname,
$metrics,
$cluster,
$hosts_up,
$hosts_down,
$always_timestamp,
$always_constant,
$data);
$dwoo->output($tpl, $data);
?>
137 changes: 32 additions & 105 deletions host_view.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?php
include_once("./global.php");

$tpl = new Dwoo_Template_File( template("host_view.tpl") );
$data = new Dwoo_Data();
$data->assign("extra", template("host_extra.tpl"));

$data->assign("cluster", $clustername);
$data->assign("host", $hostname);
$data->assign("may_edit_cluster", checkAccess( $clustername, GangliaAcl::EDIT, $conf ) );
$data->assign("may_edit_views", checkAccess( GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf) );
$data->assign("node_image", node_image($metrics));
$data->assign("sort",$sort);
$data->assign("range",$range);
$data->assign("hostname", $hostname);
Expand Down Expand Up @@ -52,55 +51,54 @@
$data->assign("additional_cluster_img_html_args", $additional_cluster_img_html_args);

foreach ( $reports["included_reports"] as $index => $report_name ) {

if ( ! in_array( $report_name, $reports["excluded_reports"] ) ) {
//$optional_reports .= "<a name=metric_" . $report_name . ">
$optional_reports .= "<a href=\"./graph_all_periods.php?$graph_args&amp;g=" . $report_name . "&amp;z=large&amp;c=$cluster_url\">";

$addMetricBtn = "<button class=\"cupid-green\" title=\"Metric Actions - Add to View, etc\" onclick=\"metricActions('{$hostname}','{$report_name}','graph',''); return false;\">+</button>";

$csvBtn = "<button title=\"Export to CSV\" class=\"cupid-green\" onClick=\"javascript:location.href='./graph.php?$graph_args&amp;g={$report_name}&amp;z=large&amp;c=$cluster_url&amp;csv=1';return false;\">CSV</button>";

$jsonBtn = "<button title=\"Export to JSON\" class=\"cupid-green\" onClick=\"javascript:location.href='./graph.php?$graph_args&amp;g={$report_name}&amp;z=large&amp;c=$cluster_url&amp;json=1';return false;\">JSON</button>";

if ( $conf['graph_engine'] == "flot" ) {
$optional_reports .= '<div class="flotheader"><span class="flottitle">' . $report_name . '</span>';
if(checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf)) {
$optional_reports .= "<button class=\"cupid-green\" title=\"Metric Actions - Add to View, etc\" onclick=\"metricActions('" . $hostname . "','" . $report_name ."','graph',''); return false;\">+</button>";
}
$optional_reports .= " <button title=\"Export to CSV\" class=\"cupid-green\" onClick=\"javascript:location.href='./graph.php?$graph_args&amp;g=" . $report_name . "&amp;z=large&amp;c=$cluster_url&amp;csv=1';return false;\">CSV</button>
<button title=\"Export to JSON\" class=\"cupid-green\" onClick=\"javascript:location.href='./graph.php?$graph_args&amp;g=" . $report_name . "&amp;z=large&amp;c=$cluster_url&amp;json=1';return false;\">JSON</button></div>";
if(checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf))
$optional_reports .= $addMetricBtn. '&nbsp;';
$optional_reports .= $csvBtn . '&nbsp;' . $jsonBtn . "</div>";
$optional_reports .= '<div id="placeholder_' . $graph_args . '&amp;g=' . $report_name .'&amp;z=medium&amp;c=' . $cluster_url . '" class="flotgraph2 img_view"></div>';
$optional_reports .= '<div id="placeholder_' . $graph_args . '&amp;g=' . $report_name .'&amp;z=medium&amp;c=' . $cluster_url . '_legend" class="flotlegend"></div>';
} else {
$graphId = $GRAPH_BASE_ID . $report_name;
$inspectBtn = "<button title=\"Inspect Graph\" onClick=\"inspectGraph('{$graph_args}&amp;g={$report_name}&amp;z=large&amp;c={$cluster_url}'); return false;\" class=\"shiny-blue\">Inspect</button>";
$showEventBtn = '<input title="Hide/Show Events" type="checkbox" id="' . $SHOW_EVENTS_BASE_ID . $report_name . '" onclick="showEvents(\'' . $graphId . '\', this.checked)"/><label class="show_event_text" for="' . $SHOW_EVENTS_BASE_ID . $report_name . '">Hide/Show Events</label>';
$optional_reports .= "<div class='img_view'>";
if(checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf)) {
$optional_reports .= "<button class=\"cupid-green\" title=\"Metric Actions - Add to View, etc\" onclick=\"metricActions('" . $hostname . "','" . $report_name ."','graph',''); return false;\">+</button>";
}
$optional_reports .= " <button title=\"Export to CSV\" class=\"cupid-green\" onClick=\"javascript:location.href='./graph.php?$graph_args&amp;g=" . $report_name . "&amp;z=large&amp;c=$cluster_url&amp;csv=1';return false;\">CSV</button>
<button title=\"Export to JSON\" class=\"cupid-green\" onClick=\"javascript:location.href='./graph.php?$graph_args&amp;g=" . $report_name . "&amp;z=large&amp;c=$cluster_url&amp;json=1';return false;\">JSON</button>
<button title=\"Inspect Graph\" onClick=\"inspectGraph('" . $graph_args . "&amp;g=" . $report_name . "&amp;z=large&amp;c=" . $cluster_url . "'); return false;\" class=\"shiny-blue\">Inspect</button>
<br /><img $additional_cluster_img_html_args border=\"0\" title=\"$cluster_url\" SRC=\"./graph.php?$graph_args&amp;g=" . $report_name ."&amp;z=medium&amp;c=$cluster_url\" style=\"padding:2px;\" />
</div>
";
if(checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf))
$optional_reports .= $addMetricBtn . '&nbsp;';
$optional_reports .= $csvBtn . '&nbsp;' . $jsonBtn . '&nbsp;' .$inspectBtn . '&nbsp;' . $showEventBtn . "<br /><img id=\"" . $graphId . "\" $additional_cluster_img_html_args border=\"0\" title=\"$cluster_url\" SRC=\"./graph.php?$graph_args&amp;g=" . $report_name ."&amp;z=medium&amp;c=$cluster_url\" style=\"padding:2px;\" />
</div>";
}

$optional_reports .= "</a>";

}

}
} // foreach

$data->assign("optional_reports", $optional_reports);



if($hosts_up)
$data->assign("node_msg", "This host is up and running.");
else
$data->assign("node_msg", "This host is down.");

$cluster_url=rawurlencode($clustername);
$data->assign("cluster_url", $cluster_url);
$data->assign("graphargs", $graph_args);

# For the node view link.
$data->assign("node_view","./?p=2&amp;c=$cluster_url&amp;h=$hostname");

getHostOverViewData($hostname,
$metrics,
$cluster,
$hosts_up,
$hosts_down,
$always_timestamp,
$always_constant,
$data);

# No reason to go on if this node is down.
if ($hosts_down)
{
Expand All @@ -119,12 +117,10 @@
if ($v['TYPE'] == "string" or $v['TYPE']=="timestamp" or
(isset($always_timestamp[$name]) and $always_timestamp[$name]))
{
$s_metrics[$name] = $v;
}
elseif ($v['SLOPE'] == "zero" or
(isset($always_constant[$name]) and $always_constant[$name]))
{
$c_metrics[$name] = $v;
}
else if (isset($reports[$name]) and $reports[$metric])
continue;
Expand Down Expand Up @@ -179,86 +175,13 @@

# in case this is not defined, set to LOCALTIME so uptime will be 0 in the display
if ( !isset($metrics['boottime']['VAL']) ){ $metrics['boottime']['VAL'] = $cluster['LOCALTIME'];}

# Add the uptime metric for this host. Cannot be done in ganglia.php,
# since it requires a fully-parsed XML tree. The classic contructor problem.
$s_metrics['uptime']['TYPE'] = "string";
$s_metrics['uptime']['VAL'] = uptime($cluster['LOCALTIME'] - $metrics['boottime']['VAL']);
$s_metrics['uptime']['TITLE'] = "Uptime";

# Add the gmond started timestamps & last reported time (in uptime format) from
# the HOST tag:
$s_metrics['gmond_started']['TYPE'] = "timestamp";
$s_metrics['gmond_started']['VAL'] = $hosts_up['GMOND_STARTED'];
$s_metrics['gmond_started']['TITLE'] = "Gmond Started";
$s_metrics['last_reported']['TYPE'] = "string";
$s_metrics['last_reported']['VAL'] = uptime($cluster['LOCALTIME'] - $hosts_up['REPORTED']);
$s_metrics['last_reported']['TITLE'] = "Last Reported";

$s_metrics['ip_address']['TITLE'] = "IP Address";
$s_metrics['ip_address']['VAL'] = $hosts_up['IP'];
$s_metrics['ip_address']['TYPE'] = "string";
$s_metrics['location']['TITLE'] = "Location";
$s_metrics['location']['VAL'] = $hosts_up['LOCATION'];
$s_metrics['location']['TYPE'] = "string";

# Show string metrics
if (is_array($s_metrics))
{
$s_metrics_data = array();
ksort($s_metrics);
foreach ($s_metrics as $name => $v )
{
# RFM - If units aren't defined for metric, make it be the empty string
! array_key_exists('UNITS', $v) and $v['UNITS'] = "";
if (isset($v['TITLE']))
{
$s_metrics_data[$name]["name"] = $v['TITLE'];
}
else
{
$s_metrics_data[$name]["name"] = $name;
}
if( $v['TYPE']=="timestamp" or (isset($always_timestamp[$name]) and $always_timestamp[$name]))
{
$s_metrics_data[$name]["value"] = date("r", $v['VAL']);
}
else
{
$s_metrics_data[$name]["value"] = $v['VAL'] . " " . $v['UNITS'];
}
}
}
$data->assign("s_metrics_data", $s_metrics_data);

# Add the average node utilization to the time & string metrics section:
$avg_cpu_num = find_avg($clustername, $hostname, "cpu_num");
if ($avg_cpu_num == 0) $avg_cpu_num = 1;
$cluster_util = sprintf("%.0f", ((double) find_avg($clustername, $hostname, "load_one") / $avg_cpu_num ) * 100);
$data->assign("name", "Avg Utilization (last $range)");
$data->assign("value", "$cluster_util%");

# Show constant metrics.
$c_metrics_data = null;
if (isset($c_metrics) and is_array($c_metrics))
{
$c_metrics_data = array();
ksort($c_metrics);
foreach ($c_metrics as $name => $v )
{
if (isset($v['TITLE']))
{
$c_metrics_data[$name]["name"] = $v['TITLE'];
}
else
{
$c_metrics_data[$name]["name"] = $name;
}
$c_metrics_data[$name]["value"] = "$v[VAL] $v[UNITS]";
}
}
$data->assign("c_metrics_data", $c_metrics_data);

$open_groups = NULL;
if (isset($_GET['metric_group']) && ($_GET['metric_group'] != "")) {
$open_groups = explode ("_|_", $_GET['metric_group']);
Expand Down Expand Up @@ -335,5 +258,9 @@
}
$data->assign("g_metrics_group_data", $g_metrics_group_data);
$data->assign("g_open_metric_groups", $g_new_open_groups);

$data->assign('GRAPH_BASE_ID', $GRAPH_BASE_ID);
$data->assign('SHOW_EVENTS_BASE_ID', $SHOW_EVENTS_BASE_ID);

$dwoo->output($tpl, $data);
?>
3 changes: 2 additions & 1 deletion js/ganglia.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ function showAllEvents(show) {
function showEvents(graphId, show) {
var graph = $("#" + graphId);
var src = graph.attr("src");
if (src.indexOf("graph.php") != 0)
if ((src.indexOf("graph.php") != 0) &&
(src.indexOf("./graph.php") != 0))
return;
var paramStr = "&event=";
paramStr += show ? "show" : "hide"
Expand Down
7 changes: 7 additions & 0 deletions templates/default/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
} else if (selected_tab == "ev") {
refreshOverlayEvent();
g_refresh_timer = setTimeout("refresh()", {$refresh} * 1000);
} else if (selected_tab == "m") {
if ($.isFunction(window.refreshHostView)) {
refreshHeader();
refreshHostView();
g_refresh_timer = setTimeout("refresh()", {$refresh} * 1000);
} else
ganglia_form.submit();
} else
ganglia_form.submit();
}
Expand Down
Loading

0 comments on commit a7f8064

Please sign in to comment.