PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ganglia/files/default/host_view.php

https://github.com/gijs/37s_cookbooks
PHP | 305 lines | 268 code | 24 blank | 13 comment | 56 complexity | db83736a717986393d7d68bb7498c217 MD5 | raw file
  1. <?php
  2. /* $Id: host_view.php 1831 2008-09-26 12:18:54Z carenas $ */
  3. $tpl = new TemplatePower( template("host_view.tpl") );
  4. $tpl->assignInclude("extra", template("host_extra.tpl"));
  5. $tpl->prepare();
  6. $tpl->assign("cluster", $clustername);
  7. $tpl->assign("host", $hostname);
  8. $tpl->assign("node_image", node_image($metrics));
  9. $tpl->assign("sort",$sort);
  10. $tpl->assign("range",$range);
  11. if($hosts_up)
  12. $tpl->assign("node_msg", "This host is up and running.");
  13. else
  14. $tpl->assign("node_msg", "This host is down.");
  15. $cluster_url=rawurlencode($clustername);
  16. $tpl->assign("cluster_url", $cluster_url);
  17. $tpl->assign("graphargs", "h=$hostname&amp;$get_metric_string&amp;st=$cluster[LOCALTIME]");
  18. # For the node view link.
  19. $tpl->assign("node_view","./?p=2&amp;c=$cluster_url&amp;h=$hostname");
  20. # No reason to go on if this node is down.
  21. if ($hosts_down)
  22. {
  23. $tpl->printToScreen();
  24. return;
  25. }
  26. $tpl->assign("ip", $hosts_up['IP']);
  27. $tpl->newBlock('columns_dropdown');
  28. $tpl->assign("metric_cols_menu", $metric_cols_menu);
  29. $g_metrics_group = array();
  30. foreach ($metrics as $name => $v)
  31. {
  32. if ($v['TYPE'] == "string" or $v['TYPE']=="timestamp" or
  33. (isset($always_timestamp[$name]) and $always_timestamp[$name]))
  34. {
  35. $s_metrics[$name] = $v;
  36. }
  37. elseif ($v['SLOPE'] == "zero" or
  38. (isset($always_constant[$name]) and $always_constant[$name]))
  39. {
  40. $c_metrics[$name] = $v;
  41. }
  42. else if (isset($reports[$name]) and $reports[$metric])
  43. continue;
  44. else
  45. {
  46. $graphargs = "c=$cluster_url&amp;h=$hostname&amp;v=$v[VAL]"
  47. ."&amp;m=$name&amp;r=$range&amp;z=medium&amp;jr=$jobrange"
  48. ."&amp;js=$jobstart&amp;st=$cluster[LOCALTIME]";
  49. # Adding units to graph 2003 by Jason Smith <smithj4@bnl.gov>.
  50. if ($v['UNITS']) {
  51. $encodeUnits = rawurlencode($v['UNITS']);
  52. $graphargs .= "&vl=$encodeUnits";
  53. }
  54. if (isset($v['TITLE'])) {
  55. $title = $v['TITLE'];
  56. $graphargs .= "&ti=$title";
  57. }
  58. $g_metrics[$name]['graph'] = $graphargs;
  59. $g_metrics[$name]['description'] = isset($v['DESC']) ? $v['DESC'] : '';
  60. # Setup an array of groups that can be used for sorting in group view
  61. if ( isset($metrics[$name]['GROUP']) ) {
  62. $groups = $metrics[$name]['GROUP'];
  63. } else {
  64. $groups = array("");
  65. }
  66. foreach ( $groups as $group) {
  67. if ( isset($g_metrics_group[$group]) ) {
  68. $g_metrics_group[$group] = array_merge($g_metrics_group[$group], (array)$name);
  69. } else {
  70. $g_metrics_group[$group] = array($name);
  71. }
  72. }
  73. }
  74. }
  75. # Add the uptime metric for this host. Cannot be done in ganglia.php,
  76. # since it requires a fully-parsed XML tree. The classic contructor problem.
  77. $s_metrics['uptime']['TYPE'] = "string";
  78. $s_metrics['uptime']['VAL'] = uptime($cluster['LOCALTIME'] - $metrics['boottime']['VAL']);
  79. $s_metrics['uptime']['TITLE'] = "Uptime";
  80. # Add the gmond started timestamps & last reported time (in uptime format) from
  81. # the HOST tag:
  82. $s_metrics['gmond_started']['TYPE'] = "timestamp";
  83. $s_metrics['gmond_started']['VAL'] = $hosts_up['GMOND_STARTED'];
  84. $s_metrics['gmond_started']['TITLE'] = "Gmond Started";
  85. $s_metrics['last_reported']['TYPE'] = "string";
  86. $s_metrics['last_reported']['VAL'] = uptime($cluster['LOCALTIME'] - $hosts_up['REPORTED']);
  87. $s_metrics['last_reported']['TITLE'] = "Last Reported";
  88. # Show string metrics
  89. if (is_array($s_metrics))
  90. {
  91. ksort($s_metrics);
  92. foreach ($s_metrics as $name => $v )
  93. {
  94. # RFM - If units aren't defined for metric, make it be the empty string
  95. ! array_key_exists('UNITS', $v) and $v['UNITS'] = "";
  96. $tpl->newBlock("string_metric_info");
  97. if (isset($v['TITLE'])) {
  98. $tpl->assign("name", $v['TITLE']);
  99. }
  100. else {
  101. $tpl->assign("name", $name);
  102. }
  103. if( $v['TYPE']=="timestamp" or (isset($always_timestamp[$name]) and $always_timestamp[$name]))
  104. {
  105. $tpl->assign("value", date("r", $v['VAL']));
  106. }
  107. else
  108. {
  109. $tpl->assign("value", $v['VAL'] . " " . $v['UNITS']);
  110. }
  111. }
  112. }
  113. # Show constant metrics.
  114. if (is_array($c_metrics))
  115. {
  116. ksort($c_metrics);
  117. foreach ($c_metrics as $name => $v )
  118. {
  119. $tpl->newBlock("const_metric_info");
  120. if (isset($v['TITLE'])) {
  121. $tpl->assign("name", $v['TITLE']);
  122. }
  123. else {
  124. $tpl->assign("name", $name);
  125. }
  126. $tpl->assign("value", "$v[VAL] $v[UNITS]");
  127. }
  128. }
  129. # Show graphs.
  130. if ( is_array($g_metrics) && is_array($g_metrics_group) )
  131. {
  132. ksort($g_metrics_group);
  133. foreach ( $g_metrics_group as $group => $metric_array )
  134. {
  135. $count = 0;
  136. if ( $group == "" ) {
  137. $group = "no_group";
  138. foreach ( $g_metrics as $name => $v ) {
  139. if ( preg_match("/diskstat/i", $name) ) {
  140. $count = $count + 1;
  141. }
  142. }
  143. }
  144. $tpl->newBlock("vol_group_info");
  145. $tpl->assign("group", $group);
  146. if ( $count > 0 )
  147. $tpl->assign("group_metric_count", ($count));
  148. else
  149. $tpl->assign("group_metric_count", count($metric_array));
  150. $i = 0;
  151. ksort($g_metrics);
  152. foreach ( $g_metrics as $name => $v )
  153. {
  154. if ( ! preg_match ("/MYSQL/i", $name) ) {
  155. if ( ! preg_match ("/memcache/i", $name) ) {
  156. if ( ! preg_match ("/haproxy/i", $name) ) {
  157. if ( in_array($name, $metric_array) ) {
  158. $tpl->newBlock("vol_metric_info");
  159. $tpl->assign("graphargs", $v['graph']);
  160. $tpl->assign("alt", "$hostname $name");
  161. if (isset($v['description']))
  162. $tpl->assign("desc", $v['description']);
  163. if ( !(++$i % $metriccols) )
  164. $tpl->assign("br", "<BR>");
  165. }
  166. }
  167. }
  168. }
  169. }
  170. }
  171. }
  172. if ( is_array($g_metrics) && is_array($g_metrics_group) )
  173. {
  174. ksort($g_metrics_group);
  175. foreach ( $g_metrics_group as $group => $metric_array )
  176. {
  177. if ( $group == "" ) {
  178. $group = "mysql";
  179. $tpl->newBlock("vol_group_info");
  180. $tpl->assign("group", $group);
  181. $tpl->assign("show", "style='display:none'");
  182. $count = 0;
  183. foreach ( $g_metrics as $name => $v )
  184. {
  185. if ( preg_match ("/MYSQL/i", $name) ) {
  186. $count = $count + 1;
  187. }
  188. }
  189. $tpl->assign("group_metric_count", $count);
  190. $i = 0;
  191. ksort($g_metrics);
  192. foreach ( $g_metrics as $name => $v )
  193. {
  194. if ( preg_match ("/MYSQL/i", $name) ) {
  195. $tpl->newBlock("vol_metric_info");
  196. $tpl->assign("graphargs", $v['graph']);
  197. $tpl->assign("alt", "$hostname $name");
  198. if (isset($v['description']))
  199. $tpl->assign("desc", $v['description']);
  200. if ( !(++$i % $metriccols) )
  201. $tpl->assign("br", "<BR>");
  202. $count = $count + 1;
  203. }
  204. }
  205. }
  206. }
  207. }
  208. if ( is_array($g_metrics) && is_array($g_metrics_group) )
  209. {
  210. ksort($g_metrics_group);
  211. foreach ( $g_metrics_group as $group => $metric_array )
  212. {
  213. if ( $group == "" ) {
  214. $group = "memcache";
  215. $tpl->newBlock("vol_group_info");
  216. $tpl->assign("group", $group);
  217. $tpl->assign("show", "style='display:none'");
  218. $count = 0;
  219. foreach ( $g_metrics as $name => $v )
  220. {
  221. if ( preg_match ("/memcache/i", $name) ) {
  222. $count = $count + 1;
  223. }
  224. }
  225. $tpl->assign("group_metric_count", $count);
  226. $i = 0;
  227. ksort($g_metrics);
  228. foreach ( $g_metrics as $name => $v )
  229. {
  230. if ( preg_match ("/memcache/i", $name) ) {
  231. $tpl->newBlock("vol_metric_info");
  232. $tpl->assign("graphargs", $v['graph']);
  233. $tpl->assign("alt", "$hostname $name");
  234. if (isset($v['description']))
  235. $tpl->assign("desc", $v['description']);
  236. if ( !(++$i % $metriccols) )
  237. $tpl->assign("br", "<BR>");
  238. $count = $count + 1;
  239. }
  240. }
  241. }
  242. }
  243. }
  244. if ( is_array($g_metrics) && is_array($g_metrics_group) )
  245. {
  246. ksort($g_metrics_group);
  247. foreach ( $g_metrics_group as $group => $metric_array )
  248. {
  249. if ( $group == "" ) {
  250. $group = "haproxy";
  251. $tpl->newBlock("vol_group_info");
  252. $tpl->assign("group", $group);
  253. $tpl->assign("show", "style='display:none'");
  254. $count = 0;
  255. foreach ( $g_metrics as $name => $v )
  256. {
  257. if ( preg_match ("/haproxy/i", $name) ) {
  258. $count = $count + 1;
  259. }
  260. }
  261. $tpl->assign("group_metric_count", $count);
  262. $i = 0;
  263. ksort($g_metrics);
  264. foreach ( $g_metrics as $name => $v )
  265. {
  266. if ( preg_match ("/haproxy/i", $name) ) {
  267. $tpl->newBlock("vol_metric_info");
  268. $tpl->assign("graphargs", $v['graph']);
  269. $tpl->assign("alt", "$hostname $name");
  270. if (isset($v['description']))
  271. $tpl->assign("desc", $v['description']);
  272. if ( !(++$i % $metriccols) )
  273. $tpl->assign("br", "<BR>");
  274. $count = $count + 1;
  275. }
  276. }
  277. }
  278. }
  279. }
  280. $tpl->printToScreen();
  281. ?>