index.php 6.0 KB

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