PageRenderTime 30ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/ganglia-3.3.7/web/host_view.php

#
PHP | 265 lines | 209 code | 40 blank | 16 comment | 63 complexity | a7abfd21e862b8021231e44a1e0bc037 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. include_once("./global.php");
  3. $tpl = new Dwoo_Template_File( template("host_view.tpl") );
  4. $data = new Dwoo_Data();
  5. $data->assign("cluster", $clustername);
  6. $data->assign("may_edit_cluster", checkAccess( $clustername, GangliaAcl::EDIT, $conf ) );
  7. $data->assign("may_edit_views", checkAccess( GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf) );
  8. $data->assign("sort",$sort);
  9. $data->assign("range",$range);
  10. $data->assign("hostname", $hostname);
  11. $data->assign("graph_engine", $conf['graph_engine']);
  12. $metric_groups_initially_collapsed = isset($conf['metric_groups_initially_collapsed']) ? $conf['metric_groups_initially_collapsed'] : TRUE;
  13. $graph_args = "h=$hostname&amp;$get_metric_string&amp;st=$cluster[LOCALTIME]";
  14. $optional_reports = "";
  15. ///////////////////////////////////////////////////////////////////////////
  16. // Let's find out what optional reports are included
  17. // First we find out what the default (site-wide) reports are then look
  18. // for host specific included or excluded reports
  19. ///////////////////////////////////////////////////////////////////////////
  20. $default_reports = array("included_reports" => array(), "excluded_reports" => array());
  21. if ( is_file($conf['conf_dir'] . "/default.json") ) {
  22. $default_reports = array_merge($default_reports,json_decode(file_get_contents($conf['conf_dir'] . "/default.json"), TRUE));
  23. }
  24. $host_file = $conf['conf_dir'] . "/host_" . $hostname . ".json";
  25. $override_reports = array("included_reports" => array(), "excluded_reports" => array());
  26. if ( is_file($host_file) ) {
  27. $override_reports = array_merge($override_reports, json_decode(file_get_contents($host_file), TRUE));
  28. }
  29. // Merge arrays
  30. $reports["included_reports"] = array_merge( $default_reports["included_reports"] , $override_reports["included_reports"]);
  31. $reports["excluded_reports"] = array_merge($default_reports["excluded_reports"] , $override_reports["excluded_reports"]);
  32. // Remove duplicates
  33. $reports["included_reports"] = array_unique($reports["included_reports"]);
  34. $reports["excluded_reports"] = array_unique($reports["excluded_reports"]);
  35. // If we want zoomable support on graphs we need to add correct zoomable class to every image
  36. $additional_cluster_img_html_args = "";
  37. $additional_host_img_css_classes = "";
  38. if ( isset($conf['zoom_support']) && $conf['zoom_support'] === true )
  39. $additional_cluster_img_html_args = "class=cluster_zoomable";
  40. $data->assign("additional_cluster_img_html_args", $additional_cluster_img_html_args);
  41. foreach ( $reports["included_reports"] as $index => $report_name ) {
  42. if ( ! in_array( $report_name, $reports["excluded_reports"] ) ) {
  43. $graph_anchor = "<a href=\"./graph_all_periods.php?$graph_args&amp;g=" . $report_name . "&amp;z=large&amp;c=$cluster_url\">";
  44. $addMetricBtn = "<button class=\"cupid-green\" title=\"Metric Actions - Add to View, etc\" onclick=\"metricActions('{$hostname}','{$report_name}','graph',''); return false;\">+</button>";
  45. $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>";
  46. $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>";
  47. if ( $conf['graph_engine'] == "flot" ) {
  48. $optional_reports .= $graph_anchor . "</a>";
  49. $optional_reports .= '<div class="flotheader"><span class="flottitle">' . $report_name . '</span>';
  50. if(checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf))
  51. $optional_reports .= $addMetricBtn. '&nbsp;';
  52. $optional_reports .= $csvBtn . '&nbsp;' . $jsonBtn . "</div>";
  53. $optional_reports .= '<div id="placeholder_' . $graph_args . '&amp;g=' . $report_name .'&amp;z=medium&amp;c=' . $cluster_url . '" class="flotgraph2 img_view"></div>';
  54. $optional_reports .= '<div id="placeholder_' . $graph_args . '&amp;g=' . $report_name .'&amp;z=medium&amp;c=' . $cluster_url . '_legend" class="flotlegend"></div>';
  55. } else {
  56. $optional_reports .= "<div class='img_view'>";
  57. $graphId = $GRAPH_BASE_ID . $report_name;
  58. $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>";
  59. $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>';
  60. if(checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf))
  61. $optional_reports .= $addMetricBtn . '&nbsp;';
  62. $optional_reports .= $csvBtn . '&nbsp;' . $jsonBtn . '&nbsp;' .$inspectBtn . '&nbsp;' . $showEventBtn . "<br />" . $graph_anchor . "<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=\"margin-top:5px;\" /></a></div>";
  63. }
  64. }
  65. } // foreach
  66. $data->assign("optional_reports", $optional_reports);
  67. $cluster_url=rawurlencode($clustername);
  68. $data->assign("cluster_url", $cluster_url);
  69. $data->assign("graphargs", $graph_args);
  70. # For the node view link.
  71. $data->assign("node_view","./?p=2&amp;c=$cluster_url&amp;h=$hostname");
  72. getHostOverViewData($hostname,
  73. $metrics,
  74. $cluster,
  75. $hosts_up,
  76. $hosts_down,
  77. $always_timestamp,
  78. $always_constant,
  79. $data);
  80. # No reason to go on if this node is down.
  81. if ($hosts_down)
  82. {
  83. $dwoo->output($tpl, $data);
  84. return;
  85. }
  86. $data->assign("ip", $hosts_up['IP']);
  87. $data->assign('columns_dropdown', 1);
  88. $data->assign("metric_cols_menu", $metric_cols_menu);
  89. $data->assign("size_menu", $size_menu);
  90. $g_metrics_group = array();
  91. foreach ($metrics as $name => $v)
  92. {
  93. if ($v['TYPE'] == "string" or $v['TYPE']=="timestamp" or
  94. (isset($always_timestamp[$name]) and $always_timestamp[$name]))
  95. {
  96. }
  97. elseif ($v['SLOPE'] == "zero" or
  98. (isset($always_constant[$name]) and $always_constant[$name]))
  99. {
  100. }
  101. else if (isset($reports[$name]) and $reports[$metric])
  102. continue;
  103. else
  104. {
  105. $size = isset($clustergraphsize) ? $clustergraphsize : 'default';
  106. $size = $size == 'medium' ? 'default' : $size; //set to 'default' to preserve old behavior
  107. // set host zoom class based on the size of the graph shown
  108. if ( isset($conf['zoom_support']) && $conf['zoom_support'] === true )
  109. $additional_host_img_css_classes = "host_${size}_zoomable";
  110. $data->assign("additional_host_img_css_classes", $additional_host_img_css_classes);
  111. $graphargs = "c=$cluster_url&amp;h=$hostname&amp;v=$v[VAL]"
  112. ."&amp;m=$name&amp;r=$range&amp;z=$size&amp;jr=$jobrange"
  113. ."&amp;js=$jobstart&amp;st=$cluster[LOCALTIME]";
  114. if ($cs)
  115. $graphargs .= "&amp;cs=" . rawurlencode($cs);
  116. if ($ce)
  117. $graphargs .= "&amp;ce=" . rawurlencode($ce);
  118. # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>.
  119. if ($v['UNITS']) {
  120. $encodeUnits = rawurlencode($v['UNITS']);
  121. $graphargs .= "&amp;vl=$encodeUnits";
  122. }
  123. if (isset($v['TITLE'])) {
  124. $title = $v['TITLE'];
  125. $encodeTitle = rawurlencode($title);
  126. $graphargs .= "&amp;ti=$encodeTitle";
  127. }
  128. $g_metrics[$name]['graph'] = $graphargs;
  129. $g_metrics[$name]['description'] = isset($v['DESC']) ? $v['DESC'] : '';
  130. $g_metrics[$name]['title'] = isset($v['TITLE']) ? $v['TITLE'] : '';
  131. # Setup an array of groups that can be used for sorting in group view
  132. if ( isset($metrics[$name]['GROUP']) ) {
  133. $groups = $metrics[$name]['GROUP'];
  134. } else {
  135. $groups = array("");
  136. }
  137. foreach ( $groups as $group) {
  138. if ( isset($g_metrics_group[$group]) ) {
  139. $g_metrics_group[$group] = array_merge($g_metrics_group[$group], (array)$name);
  140. } else {
  141. $g_metrics_group[$group] = array($name);
  142. }
  143. }
  144. }
  145. }
  146. # in case this is not defined, set to LOCALTIME so uptime will be 0 in the display
  147. if ( !isset($metrics['boottime']['VAL']) ){ $metrics['boottime']['VAL'] = $cluster['LOCALTIME'];}
  148. # Add the average node utilization to the time & string metrics section:
  149. $avg_cpu_num = find_avg($clustername, $hostname, "cpu_num");
  150. if ($avg_cpu_num == 0) $avg_cpu_num = 1;
  151. $cluster_util = sprintf("%.0f", ((double) find_avg($clustername, $hostname, "load_one") / $avg_cpu_num ) * 100);
  152. $data->assign("name", "Avg Utilization (last $range)");
  153. $data->assign("value", "$cluster_util%");
  154. $open_groups = NULL;
  155. if (isset($_GET['metric_group']) && ($_GET['metric_group'] != "")) {
  156. $open_groups = explode ("_|_", $_GET['metric_group']);
  157. } else {
  158. if (isset($_SESSION['metric_group']) && ($_SESSION['metric_group'] != ""))
  159. $open_groups = explode ("_|_", $_SESSION['metric_group']);
  160. }
  161. $g_new_open_groups = ""; // Updated definition of currently open metric groups
  162. # Show graphs.
  163. if ( is_array($g_metrics) && is_array($g_metrics_group) )
  164. {
  165. $g_metrics_group_data = array();
  166. ksort($g_metrics_group);
  167. $host_metrics = 0;
  168. if ($open_groups == NULL) {
  169. if ($metric_groups_initially_collapsed)
  170. $g_new_open_groups = "NOGROUPS";
  171. else
  172. $g_new_open_groups = "ALLGROUPS";
  173. } else
  174. $g_new_open_groups .= $open_groups[0];
  175. foreach ( $g_metrics_group as $group => $metric_array )
  176. {
  177. if ( $group == "" ) {
  178. $group = "no_group";
  179. }
  180. $c = count($metric_array);
  181. $g_metrics_group_data[$group]["group_metric_count"] = $c;
  182. $host_metrics += $c;
  183. if ($open_groups == NULL)
  184. $g_metrics_group_data[$group]["visible"] =
  185. ! $metric_groups_initially_collapsed;
  186. else {
  187. $inList = in_array($group, $open_groups);
  188. $g_metrics_group_data[$group]["visible"] =
  189. ((($open_groups[0] == "NOGROUPS") && $inList) ||
  190. ($open_groups[0] == "ALLGROUPS" && !$inList));
  191. }
  192. $visible = $g_metrics_group_data[$group]["visible"];
  193. if (($visible && ($open_groups[0] == "NOGROUPS")) ||
  194. (!$visible && ($open_groups[0] == "ALLGROUPS")))
  195. $g_new_open_groups .= "_|_" . $group;
  196. $i = 0;
  197. ksort($g_metrics);
  198. foreach ( $g_metrics as $name => $v )
  199. {
  200. if ( in_array($name, $metric_array) ) {
  201. $g_metrics_group_data[$group]["metrics"][$name]["graphargs"] = $v['graph'];
  202. $g_metrics_group_data[$group]["metrics"][$name]["alt"] = "$hostname $name";
  203. $g_metrics_group_data[$group]["metrics"][$name]["host_name"] = $hostname;
  204. $g_metrics_group_data[$group]["metrics"][$name]["metric_name"] = $name;
  205. $g_metrics_group_data[$group]["metrics"][$name]["title"] = $v['title'];
  206. $g_metrics_group_data[$group]["metrics"][$name]["desc"] = $v['description'];
  207. $g_metrics_group_data[$group]["metrics"][$name]["new_row"] = "";
  208. if ( !(++$i % $conf['metriccols']) && ($i != $c) )
  209. $g_metrics_group_data[$group]["metrics"][$name]["new_row"] = "</TR><TR>";
  210. }
  211. }
  212. }
  213. $data->assign("host_metrics_count", $host_metrics);
  214. }
  215. $_SESSION['metric_group'] = $g_new_open_groups;
  216. if ( $conf['graph_engine'] == "flot" ) {
  217. $data->assign("graph_height", $conf['graph_sizes'][$size]["height"] + 50);
  218. $data->assign("graph_width", $conf['graph_sizes'][$size]["width"]);
  219. }
  220. $data->assign("g_metrics_group_data", $g_metrics_group_data);
  221. $data->assign("g_open_metric_groups", $g_new_open_groups);
  222. $data->assign('GRAPH_BASE_ID', $GRAPH_BASE_ID);
  223. $data->assign('SHOW_EVENTS_BASE_ID', $SHOW_EVENTS_BASE_ID);
  224. $dwoo->output($tpl, $data);
  225. ?>