PageRenderTime 29ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/debs/ganglia/ganglia-3.1.2/web/meta_view.php

https://github.com/ChuguluGames/mediawiki-svn
PHP | 218 lines | 181 code | 15 blank | 22 comment | 38 complexity | 255eae79189db3a301e9cf44b181bed5 MD5 | raw file
  1. <?php
  2. /* $Id: meta_view.php 1710 2008-08-21 16:44:54Z bernardli $ */
  3. $tpl = new TemplatePower( template("meta_view.tpl") );
  4. $tpl->prepare();
  5. # Find the private clusters. But no one is emabarrassed in the
  6. # control room (public only!).
  7. if ( $context != "control" ) {
  8. $private=embarrassed();
  9. }
  10. $source_names = array_keys($grid);
  11. # Build a list of cluster names and randomly pick a smaller subset to
  12. # display for control room mode. This allows a dedicated host to
  13. # eventually cycle through all the graphs w/o scrolling the mouse. A bunch
  14. # of these stations could monitor a large grid.
  15. #
  16. # For the standard meta view still display all the hosts.
  17. if ( $context == "control" ) {
  18. srand((double)microtime()*1000000);
  19. shuffle($source_names);
  20. $subset = array_slice($source_names, 0, abs($controlroom));
  21. $source_names = $subset;
  22. }
  23. foreach( $source_names as $c)
  24. {
  25. $cpucount = $metrics[$c]["cpu_num"]['SUM'];
  26. if (!$cpucount) $cpucount=1;
  27. $load_one = $metrics[$c]["load_one"]['SUM'];
  28. $value = (double) $load_one / $cpucount;
  29. $sorted_sources[$c] = $value;
  30. $values[$c] = $value;
  31. isset($total_load) or $total_load = 0;
  32. $total_load += $value;
  33. }
  34. if ($sort == "descending") {
  35. $sorted_sources[$self] = 999999999;
  36. arsort($sorted_sources);
  37. } else if ($sort == "by name") { # SORT HACK to keep $self first; see below:
  38. $sorted_sources["AAAAA.$self"] = $sorted_sources[$self];
  39. unset($sorted_sources[$self]);
  40. ksort($sorted_sources);
  41. } else if ($sort == "by hosts up") {
  42. foreach ($sorted_sources as $source => $val) {
  43. $sorted_sources[$source] = intval($grid[$source]['HOSTS_UP']);
  44. }
  45. $sorted_sources[$self] = 999999999;
  46. arsort($sorted_sources);
  47. } else if ($sort == "by hosts down") {
  48. foreach ($sorted_sources as $source => $val) {
  49. $sorted_sources[$source] = intval($grid[$source]['HOSTS_DOWN']);
  50. }
  51. $sorted_sources[$self] = 999999999;
  52. arsort($sorted_sources);
  53. } else {
  54. $sorted_sources[$self] = -1;
  55. asort($sorted_sources);
  56. }
  57. # Display the sources. The first is ourself, the rest are our children.
  58. foreach ( $sorted_sources as $source => $val )
  59. {
  60. # XXX: SORT HACK to keep $self first; see above
  61. if ($source == "AAAAA.$self") {
  62. $source = $self;
  63. }
  64. $m = $metrics[$source];
  65. $sourceurl = rawurlencode($source);
  66. if (isset($grid[$source]['GRID']) and $grid[$source]['GRID'])
  67. {
  68. $localtime = $grid[$source]['LOCALTIME'];
  69. # Is this the our own grid?
  70. if ($source==$self)
  71. {
  72. # Negative control room values means dont display grid summary.
  73. if ($controlroom < 0) continue;
  74. $num_sources = count($sorted_sources) - 1;
  75. $name = "$self $meta_designator ($num_sources sources)";
  76. $graph_url = "me=$sourceurl&amp;$get_metric_string";
  77. $url = "./?$get_metric_string";
  78. }
  79. else
  80. {
  81. # Set grid context.
  82. $name = "$source $meta_designator";
  83. $graph_url = "G=$sourceurl&amp;$get_metric_string&amp;st=$localtime";
  84. $authority = $grid[$source]['AUTHORITY'];
  85. $url = "$authority?gw=fwd&amp;gs=$gridstack_url";
  86. }
  87. $alt_url = "<a href=\"./?t=yes&amp;$get_metric_string\">(tree view)</a>";
  88. $class = "grid";
  89. }
  90. else
  91. {
  92. # Set cluster context.
  93. $name = $source;
  94. $localtime = $grid[$source]['LOCALTIME'];
  95. $graph_url = "c=$sourceurl&amp;$get_metric_string&amp;st=$localtime";
  96. $url = "./?c=$sourceurl&amp;$get_metric_string";
  97. $alt_url = "<a href=\"./?p=2&amp;$graph_url\">(physical view)</a>";
  98. $class = "cluster";
  99. }
  100. $cpu_num = $m["cpu_num"]['SUM'] ? $m["cpu_num"]['SUM'] : 1;
  101. $cluster_load15 = sprintf("%.0f", ((double) $m["load_fifteen"]['SUM'] / $cpu_num) * 100);
  102. $cluster_load5 = sprintf("%.0f", ((double) $m["load_five"]['SUM'] / $cpu_num) * 100);
  103. $cluster_load1 = sprintf("%.0f", ((double) $m["load_one"]['SUM'] / $cpu_num) * 100);
  104. $cluster_load = "$cluster_load15%, $cluster_load5%, $cluster_load1%";
  105. $tpl->newBlock ("source_info");
  106. $tpl->assign("name", $name );
  107. $tpl->assign("cpu_num", $m["cpu_num"]['SUM']);
  108. $tpl->assign("url", $url);
  109. $tpl->assign("class", $class);
  110. if (isset($num_sources))
  111. $tpl->assign("Sources: $num_sources");
  112. # I dont like this either, but we need to have private clusters because some
  113. # users are skittish about publishing the load info.
  114. if (!isset($private[$source]) or !$private[$source])
  115. {
  116. $tpl->assign("alt_view", "<FONT SIZE=\"-2\">$alt_url</FONT>");
  117. # Each block has a different namespace, so we need to redefine variables.
  118. $tpl->newBlock("public");
  119. if ($localtime)
  120. $tpl->assign("localtime", "<font size=-1>Localtime:</font><br>&nbsp;&nbsp;"
  121. . date("Y-m-d H:i", $localtime) );
  122. if ($cluster_load)
  123. $tpl->assign("cluster_load", "<font size=-1>Avg Load (15, 5, 1m):</font>"
  124. ."<br>&nbsp;&nbsp;$cluster_load");
  125. $tpl->assign("cpu_num", $m["cpu_num"]['SUM']);
  126. $tpl->assign("num_nodes", $grid[$source]["HOSTS_UP"] );
  127. $tpl->assign("num_dead_nodes", $grid[$source]["HOSTS_DOWN"] );
  128. $tpl->assign("range", $range);
  129. $tpl->assign("name", $name );
  130. $tpl->assign("url", $url);
  131. $tpl->assign("graph_url", $graph_url);
  132. if(isset($base64img)) {
  133. $tpl->assign("base64img", $base64img);
  134. }
  135. }
  136. else
  137. {
  138. $tpl->newBlock("private");
  139. $tpl->assign("num_nodes", $grid[$source]["HOSTS_UP"] + $grid[$source]["HOSTS_DOWN"] );
  140. $tpl->assign("cpu_num", $m["cpu_num"]['SUM']);
  141. if ($localtime)
  142. $tpl->assign("localtime", "<font size=-1>Localtime:</font><br>&nbsp;&nbsp;"
  143. . date("Y-m-d H:i",$localtime));
  144. }
  145. }
  146. # Show load images.
  147. if ($show_meta_snapshot=="yes") {
  148. $tpl->newBlock("show_snapshot");
  149. $tpl->assign("self", "$self $meta_designator");
  150. foreach ($sorted_sources as $c=>$value) {
  151. if ($c==$self) continue;
  152. if ($c=="AAAAA.$self") continue; # SORT HACK; see above
  153. if (isset($private[$c]) and $private[$c]) {
  154. $Private[$c] = template("images/cluster_private.jpg");
  155. continue;
  156. }
  157. $names[]=$c;
  158. if (isset($grid[$c]['GRID']) and $grid[$c]['GRID'])
  159. $image = load_image("grid", $values[$c]);
  160. else
  161. $image = load_image("cluster", $values[$c]);
  162. $Images[]=$image;
  163. }
  164. # Add private cluster pictures to the end.
  165. if (isset($Private) and is_array($Private)) {
  166. foreach ($Private as $c=>$image) {
  167. $names[]=$c;
  168. $Images[]=$image;
  169. }
  170. }
  171. # All this fancyness is to get the Cluster names
  172. # above the image. Not easy with template blocks.
  173. $cols=5;
  174. $i = 0;
  175. $count=count($names);
  176. while ($i < $count)
  177. {
  178. $snapnames = "";
  179. $snapimgs = "";
  180. $tpl->newBlock("snap_row");
  181. foreach(range(0, $cols-1) as $j)
  182. {
  183. $k = $i + $j;
  184. if ($k >= $count) break;
  185. $n = $names[$k];
  186. $snapnames .= "<td valign=bottom align=center><b>$n</b></td>\n";
  187. $snapimgs .= "<td valign=top align=center>";
  188. if (isset($grid[$n]['GRID']) and $grid[$n]['GRID'])
  189. $snapimgs .= "<a href=\"" . $grid[$n]['AUTHORITY'] ."?gw=fwd&amp;gs=$gridstack_url\">";
  190. else
  191. {
  192. $nameurl = rawurlencode($n);
  193. $snapimgs .= "<a href=\"./?c=$nameurl&amp;$get_metric_string\">";
  194. }
  195. $snapimgs .= "<img src=$Images[$k] border=0 align=top></a></td>\n";
  196. }
  197. $tpl->assign("names", $snapnames);
  198. $tpl->assign("images", $snapimgs);
  199. $i += $cols;
  200. }
  201. }
  202. $tpl->printToScreen();
  203. ?>