index.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. require_once('datasources.inc');
  3. require_once('class_cpu.inc');
  4. require_once('class_if.inc');
  5. require_once('class_io.inc');
  6. require_once('class_mem.inc');
  7. require_once('class_pf.inc');
  8. if (!empty($GLOBALS["QUERY_STRING"])) {
  9. $args = $GLOBALS["QUERY_STRING"];
  10. // rework args to contain ony last set 'command'
  11. $options = array();
  12. $allargs = explode('&', $args);
  13. $i = 0;
  14. while ($i < count($allargs)) {
  15. $operand = split('=', $allargs[$i]);
  16. if (count($operand) == 2) {
  17. $options[$operand[0]]=$operand[1];
  18. }
  19. $i++;
  20. }
  21. // decode done, now recode
  22. $i = 0;
  23. $args = "";
  24. reset($options);
  25. while (list($key,$val) = each($options)) {
  26. if ($args) {
  27. $args .= '&';
  28. }
  29. $args .= $key.'='.$val;
  30. }
  31. } else {
  32. $args = "";
  33. }
  34. function make_graph_url($type, $new_args) {
  35. global $args;
  36. $new_args = urlencode($new_args);
  37. $url = "graph_".$type.".php?";
  38. $allargs="";
  39. if ($args) {
  40. $allargs.=$args.'&';
  41. }
  42. $allargs .= $new_args;
  43. switch ($type) {
  44. case 'cpu':
  45. $g = new CPU_Graph();
  46. break;
  47. case 'if':
  48. $g = new IF_Graph();
  49. break;
  50. case 'io':
  51. $g = new IO_Graph();
  52. break;
  53. case 'mem':
  54. $g = new MEM_Graph();
  55. break;
  56. case 'pf':
  57. $g = new PF_Graph();
  58. }
  59. $g->execute($allargs);
  60. return ($url . $g->settings2url());
  61. }
  62. function print_index_url($new_args) {
  63. global $args;
  64. $url = 'index.php?';
  65. if ($args) {
  66. $url.=$args.'&';
  67. }
  68. $url .= sprintf("%s", $new_args);
  69. print $url;
  70. }
  71. ?>
  72. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
  73. <html>
  74. <head>
  75. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  76. <title>mon statistics</title>
  77. <link rel="stylesheet" href="mon.css" type="text/css" />
  78. </head>
  79. <body>
  80. <table border="0" cellspacing="0" cellpadding="0" align="center">
  81. <tr>
  82. <td valign="top">
  83. <table border="0" cellpadding="0" cellspacing="0">
  84. <tr>
  85. <td width="5%"/></td>
  86. <td colspan="5" bgcolor="#555599"><img src="spacer.png" width="1" height="1" /></td>
  87. <td width="5%"/></td>
  88. </tr>
  89. <tr>
  90. <!-- sidebar -->
  91. <td width="5%"/></td>
  92. <td width="1" bgcolor="#555599"><img src="spacer.png" width="1" height="1" /></td>
  93. <td bgcolor="#FFFFFF" valign="top" width="20%">
  94. <div class="left">
  95. <img src="mon.png" width="149" border="0" alt="[mon]" />
  96. </div>
  97. <div class="left">
  98. <div class="section-head">Graph Options</div>
  99. <div class="left-links">
  100. Timespan:
  101. <a href="<? print_index_url("start=-14515200") ?>">last 6 months</a>,
  102. <a href="<? print_index_url("start=-2419200") ?>">last month</a>,
  103. <a href="<? print_index_url("start=-691200") ?>">last 8 days</a>,
  104. <a href="<? print_index_url("start=-86400") ?>">last 24 hours</a>,
  105. <a href="<? print_index_url("start=-3600") ?>">last hour</a><br />
  106. Size:
  107. <a href="<? print_index_url("size=tiny") ?>">tiny</a>,
  108. <a href="<? print_index_url("size=small") ?>">small</a>,
  109. <a href="<? print_index_url("size=normal") ?>">normal</a>,
  110. <a href="<? print_index_url("size=big") ?>">big</a>,
  111. <a href="<? print_index_url("size=huge") ?>">huge</a><br />
  112. </div>
  113. <div class="section-head">Type options</div>
  114. <div class="left-links">
  115. Cpu:
  116. <a href="<? print_index_url("cpu=brief")?> ">brief</a>,
  117. <a href="<? print_index_url("cpu=detailed")?> ">detailed</a><br />
  118. If:
  119. <a href="<? print_index_url("if=brief")?> ">brief</a>,
  120. <a href="<? print_index_url("if=bits")?> ">bits</a>,
  121. <a href="<? print_index_url("if=packets")?> ">packets</a>,
  122. <a href="<? print_index_url("if=all")?> ">all</a><br />
  123. Io:
  124. <a href="<? print_index_url("io=brief")?> ">brief</a>,
  125. <a href="<? print_index_url("io=all")?> ">all</a><br />
  126. Mem:
  127. <a href="<? print_index_url("mem=brief")?> ">brief</a>,
  128. <a href="<? print_index_url("mem=detailed")?> ">detailed</a><br />
  129. </div>
  130. </div>
  131. </td>
  132. <!-- main window -->
  133. <td width="1" bgcolor="#555599"><img src="spacer.png" width="1" height="1" /></td>
  134. <td bgcolor="#FFFFFF" valign="top" width="95%">
  135. <div align="center" class="blue">
  136. <table bgcolor="#6699CC" border="0" cellpadding="0" cellspacing="0">
  137. <tr>
  138. <?
  139. $root_dir = dir($mon2web["tree"]);
  140. while ($machine = $root_dir->read()) {
  141. if ($machine != '.' &&
  142. $machine != '..' &&
  143. is_dir($mon2web["tree"]."/".$machine)) {
  144. print '
  145. <td><a class="blue" href="';
  146. print_index_url("#" . $machine);
  147. print '">'. $machine . '</a>&nbsp;&nbsp;&nbsp;</td>
  148. ';
  149. }
  150. }
  151. ?>
  152. </tr>
  153. </table>
  154. </div>
  155. <div class="items">
  156. <?php
  157. // traverse through the monrrd tree
  158. $root_dir = dir($mon2web["tree"]);
  159. $found_machine = 0;
  160. while ($machine = $root_dir->read()) {
  161. if ($machine != '.' &&
  162. $machine != '..' &&
  163. is_dir($mon2web["tree"]."/".$machine)) {
  164. print '
  165. <!-- item start -->
  166. <div class="header">
  167. <a class="header" name="'. $machine . '">'. $machine. '</a><br />
  168. </div>
  169. ';
  170. $machine_dir = dir($mon2web["tree"]."/".$machine);
  171. while ($filename = $machine_dir->read()) {
  172. $file = $mon2web["tree"]."/".$machine."/".$filename;
  173. if (is_file($file) &&
  174. preg_match("/^(cpu|if|io|mem|pf)(_([a-z]+))?([0-9]?).rrd$/",
  175. $filename, $match)) {
  176. $rrdtype = $match[1];
  177. $rrdwhat = $match[3];
  178. $rrdwhich = $match[4];
  179. $cmd = make_graph_url($rrdtype,
  180. "rrdfile=".$file.
  181. "&name=".$rrdwhat.$rrdwhich);
  182. print '<img src="' . $cmd . '">'."\n";
  183. $found_machine++;
  184. }
  185. }
  186. print '
  187. <div class="item-footer"></div>
  188. ';
  189. }
  190. }
  191. if ($found_machine == 0) {
  192. print 'Did not find any host directories in '.$mon2web["tree"].'<br>';
  193. }
  194. ?>
  195. <div class="copyright">Copyright &copy; 2002 Willem Dijkstra</div>
  196. </div> <!-- end items div -->
  197. </td> <!-- end main window -->
  198. <!-- horizontal endline -->
  199. <td width="1" bgcolor="#555599"><img src="spacer.png" width="1" height="1" /></td>
  200. </tr>
  201. <!-- vertical endline -->
  202. <tr>
  203. <td width="5%"/></td>
  204. <td colspan="5" bgcolor="#555599"><img src="spacer.png" width="1" height="1" /></td>
  205. <td width="5%"/></td>
  206. </tr>
  207. </table>
  208. </td>
  209. <td width="5%"/></td>
  210. </tr>
  211. </table>
  212. </body>
  213. </html>