index.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <?php
  2. // $Id: index.php,v 1.16 2002/12/29 16:19:36 dijkstra Exp $
  3. require_once('datasources.inc');
  4. require_once('class_cpu.inc');
  5. require_once('class_if.inc');
  6. require_once('class_io.inc');
  7. require_once('class_mem.inc');
  8. require_once('class_pf.inc');
  9. require_once('class_debug.inc');
  10. require_once('class_proc.inc');
  11. if (!empty($HTTP_SERVER_VARS["QUERY_STRING"])) {
  12. $args = $HTTP_SERVER_VARS["QUERY_STRING"];
  13. // rework args to contain ony last set 'command'
  14. $options = array();
  15. $allargs = explode('&', $args);
  16. $i = 0;
  17. $selected_machine = "";
  18. while ($i < count($allargs)) {
  19. $operand = split('=', $allargs[$i]);
  20. if (count($operand) == 2) {
  21. // options for this page
  22. if ($operand[0] == "machine") {
  23. $selected_machine = $operand[1];
  24. }
  25. $options[$operand[0]]=$operand[1];
  26. }
  27. $i++;
  28. }
  29. // decode done, now recode
  30. $i = 0;
  31. $args = "";
  32. reset($options);
  33. while (list($key,$val) = each($options)) {
  34. if ($args) {
  35. $args .= '&';
  36. }
  37. $args .= $key.'='.$val;
  38. }
  39. } else {
  40. $args = "";
  41. $selected_machine = "";
  42. }
  43. function make_graph_url($type, $new_args) {
  44. global $args;
  45. $new_args = urlencode($new_args);
  46. $url = "graph_".$type.".php?";
  47. $allargs="";
  48. if ($args) {
  49. $allargs.=$args.'&';
  50. }
  51. $allargs .= $new_args;
  52. switch ($type) {
  53. case 'cpu':
  54. $g = new CPU_Graph();
  55. break;
  56. case 'if':
  57. $g = new IF_Graph();
  58. break;
  59. case 'io':
  60. $g = new IO_Graph();
  61. break;
  62. case 'mem':
  63. $g = new MEM_Graph();
  64. break;
  65. case 'pf':
  66. $g = new PF_Graph();
  67. break;
  68. case 'debug':
  69. $g = new DEBUG_Graph();
  70. break;
  71. case 'proc':
  72. $g = new PROC_Graph();
  73. break;
  74. }
  75. $g->execute($allargs);
  76. return ($url . $g->settings2url());
  77. }
  78. function print_index_url($new_args) {
  79. global $args;
  80. $url = 'index.php?';
  81. if ($args) {
  82. $url.=$args.'&';
  83. }
  84. $url .= sprintf("%s", $new_args);
  85. print $url;
  86. }
  87. ?>
  88. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
  89. <html>
  90. <head>
  91. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  92. <title>symon statistics</title>
  93. <link rel="stylesheet" href="symon.css" type="text/css" />
  94. </head>
  95. <body>
  96. <table border="0" cellspacing="0" cellpadding="0" align="center">
  97. <tr>
  98. <td valign="top">
  99. <table border="0" cellpadding="0" cellspacing="0">
  100. <tr>
  101. <td width="5%"></td>
  102. <td colspan="5" bgcolor="#555599"><img src="spacer.png" width="1" height="1" alt="|"/></td>
  103. <td width="5%"></td>
  104. </tr>
  105. <tr>
  106. <!-- sidebar -->
  107. <td width="5%"></td>
  108. <td width="1" bgcolor="#555599"><img src="spacer.png" width="1" height="1" alt="|"/></td>
  109. <td bgcolor="#FFFFFF" valign="top" width="20%">
  110. <div class="left">
  111. <img src="symon.png" width="149" border="0" alt="[symon]" />
  112. </div>
  113. <div class="left">
  114. <div class="section-head">Graph Options</div>
  115. <div class="left-links">
  116. Timespan:
  117. <a href="<? print_index_url("start=-14515200") ?>">last 6 months</a>,
  118. <a href="<? print_index_url("start=-2419200") ?>">last month</a>,
  119. <a href="<? print_index_url("start=-691200") ?>">last 8 days</a>,
  120. <a href="<? print_index_url("start=-86400") ?>">last 24 hours</a>,
  121. <a href="<? print_index_url("start=-3600") ?>">last hour</a><br />
  122. Size:
  123. <a href="<? print_index_url("size=tiny") ?>">tiny</a>,
  124. <a href="<? print_index_url("size=small") ?>">small</a>,
  125. <a href="<? print_index_url("size=normal") ?>">normal</a>,
  126. <a href="<? print_index_url("size=big") ?>">big</a>,
  127. <a href="<? print_index_url("size=huge") ?>">huge</a><br />
  128. </div>
  129. <div class="section-head">Type options</div>
  130. <div class="left-links">
  131. Cpu:
  132. <a href="<? print_index_url("cpu=brief")?> ">brief</a>,
  133. <a href="<? print_index_url("cpu=detailed")?> ">detailed</a><br />
  134. If:
  135. <a href="<? print_index_url("if=brief")?> ">brief</a>,
  136. <a href="<? print_index_url("if=bits")?> ">bits</a>,
  137. <a href="<? print_index_url("if=packets")?> ">packets</a>,
  138. <a href="<? print_index_url("if=all")?> ">all</a><br />
  139. Io:
  140. <a href="<? print_index_url("io=brief")?> ">brief</a>,
  141. <a href="<? print_index_url("io=all")?> ">all</a><br />
  142. Mem:
  143. <a href="<? print_index_url("mem=brief")?> ">brief</a>,
  144. <a href="<? print_index_url("mem=detailed")?> ">detailed</a><br />
  145. Pf:
  146. <a href="<? print_index_url("pf=state")?> ">state</a>,
  147. <a href="<? print_index_url("pf=performance")?> ">performance</a>,
  148. <a href="<? print_index_url("pf=all")?> ">all</a><br />
  149. Proc:
  150. <a href="<? print_index_url("proc=brief")?> ">brief</a>,
  151. <a href="<? print_index_url("proc=detailed")?> ">detailed</a><br />
  152. Debug:
  153. <a href="<? print_index_url("debug=brief")?> ">brief</a>,
  154. <a href="<? print_index_url("debug=detailed")?> ">detailed</a><br />
  155. </div>
  156. </div>
  157. </td>
  158. <!-- main window -->
  159. <td width="1" bgcolor="#555599"><img src="spacer.png" width="1" height="1"></td>
  160. <td bgcolor="#FFFFFF" valign="top" width="95%">
  161. <div align="center" class="blue">
  162. <table bgcolor="#6699CC" border="0" cellpadding="0" cellspacing="0">
  163. <tr>
  164. <?
  165. // get machines
  166. $root_dir = dir($symon2web["tree"]);
  167. while ($machine = $root_dir->read()) {
  168. if ($machine != '.' &&
  169. $machine != '..' &&
  170. is_dir($symon2web["tree"]."/".$machine)) {
  171. $symon2web["machine"][$machine] = $symon2web["tree"]."/".$machine;
  172. if ($machine == $selected_machine) {
  173. $selected_dir = $symon2web["machine"][$machine];
  174. }
  175. }
  176. }
  177. // show blue bar
  178. if ($symon2web["view"] == "one") {
  179. print '
  180. <td><a class="blue" href="';
  181. print_index_url("machine=all");
  182. print '">all machines</a>&nbsp;&nbsp;&nbsp;</td>
  183. ';
  184. }
  185. reset($symon2web["machine"]);
  186. while (list($machine, $dir) = each($symon2web["machine"])) {
  187. print '
  188. <td><a class="blue" href="';
  189. if ($symon2web["view"] == "one") {
  190. print_index_url("machine=" . $machine);
  191. } else {
  192. print_index_url("#" . $machine);
  193. }
  194. print '">'. $machine . "</a>&nbsp;&nbsp;&nbsp;</td>\n";
  195. }
  196. ?>
  197. </tr>
  198. </table>
  199. </div>
  200. <div class="items">
  201. <?php
  202. // traverse through the symonrrd tree
  203. $found_machine = 0;
  204. // TODO : check if machine is a list
  205. reset($symon2web["machine"]);
  206. // only allow a single machine in the machine array if selected machine is set
  207. if ($symon2web["view"] == "one" && $selected_machine != "all" ) {
  208. unset($symon2web["machine"]);
  209. if ($selected_machine) {
  210. $symon2web["machine"][$selected_machine] = $selected_dir;
  211. }
  212. }
  213. // show graphs for each machine in the machine array
  214. while (list($machine, $dir) = each($symon2web["machine"])) {
  215. print '
  216. <!-- item start -->
  217. <div class="header">
  218. <a class="header" name="'. $machine . '">'. $machine. '</a><br />
  219. </div>
  220. ';
  221. $machine_dir = dir($dir);
  222. while ($filename = $machine_dir->read()) {
  223. $file = $dir."/".$filename;
  224. if (is_file($file) &&
  225. preg_match("/^(cpu|if|io|mem|pf|proc|debug)(_([a-z]+))?([0-9]?).rrd$/",
  226. $filename, $match)) {
  227. $rrdtype = $match[1];
  228. $rrdwhat = $match[3];
  229. $rrdwhich = $match[4];
  230. $cmd = make_graph_url($rrdtype,
  231. "rrdfile=".$file.
  232. "&name=".$rrdwhat.$rrdwhich);
  233. if ($symon2web["magnify"] != '') {
  234. $magcmd = make_graph_url($rrdtype,
  235. "rrdfile=".$file.
  236. "&name=".$rrdwhat.$rrdwhich.
  237. "&size=".$symon2web["magnify"]);
  238. print '<a class="graph" href="'. $magcmd . '"> <img src="' . $cmd .
  239. '" alt="'. $rrdtype . $rrdwhat . $rrdwhich .'"></a>'."\n";
  240. } else {
  241. print '<img src="' . $cmd . '" alt="'. $rrdtype . $rrdwhat . $rrdwhich .'">'."\n";
  242. }
  243. $found_machine++;
  244. }
  245. }
  246. print '
  247. <div class="item-footer"></div>
  248. ';
  249. }
  250. if ($found_machine == 0) {
  251. if ($symon2web["view"] == "one") {
  252. print 'Please select a machine';
  253. } else {
  254. print 'Did not find any host directories in '.$symon2web["tree"].'<br>';
  255. }
  256. }
  257. ?>
  258. <div class="copyright">Copyright &copy; 2002 Willem Dijkstra</div>
  259. </div> <!-- end items div -->
  260. </td> <!-- end main window -->
  261. <!-- horizontal endline -->
  262. <td width="1" bgcolor="#555599"><img src="spacer.png" width="1" height="1" alt="|" /></td>
  263. </tr>
  264. <!-- vertical endline -->
  265. <tr>
  266. <td width="5%"></td>
  267. <td colspan="5" bgcolor="#555599"><img src="spacer.png" width="1" height="1" alt="|" /></td>
  268. <td width="5%"></td>
  269. </tr>
  270. </table>
  271. </td>
  272. <td width="5%"></td>
  273. </tr>
  274. </table>
  275. </body>
  276. </html>