2 |
|
|
3 |
|
# |
4 |
|
# i-scream central monitoring system |
5 |
< |
# http://www.i-scream.org.uk |
5 |
> |
# http://www.i-scream.org |
6 |
|
# Copyright (C) 2000-2002 i-scream |
7 |
|
# |
8 |
|
# This program is free software; you can redistribute it and/or |
20 |
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 |
|
# |
22 |
|
|
23 |
– |
# Navigation for the i-scream reports. |
24 |
– |
# pjm2@ukc.ac.uk |
25 |
– |
# |
23 |
|
# CONFIGURABLE CONSTANTS: - |
24 |
|
|
25 |
|
include("latest_config.inc.php"); |
29 |
|
|
30 |
|
include("iutils.inc.php"); |
31 |
|
|
32 |
+ |
if ($formMethod == "GET") { |
33 |
+ |
$machine = isset($_GET['machine']) ? $_GET['machine'] : ""; |
34 |
+ |
} |
35 |
+ |
|
36 |
+ |
|
37 |
|
function printLine($title) { |
38 |
|
echo "<hr style=\"color:#9999ff;\">"; |
39 |
|
echo "<b>$title</b>"; |
40 |
|
} |
41 |
|
|
42 |
|
|
43 |
< |
function showStat($title, $value, $input) { |
43 |
> |
function showUptime($title, $value, $input, $graph="") { |
44 |
> |
$report = $value; |
45 |
|
|
46 |
+ |
$value = getPregMatch($value, $input); |
47 |
+ |
if (!isset($value)) { |
48 |
+ |
$value = "<i><font color=\"#999999\">not sent</font></i>"; |
49 |
+ |
} |
50 |
+ |
?> |
51 |
+ |
<table border="0" width="100%"> |
52 |
+ |
<tr> |
53 |
+ |
<td width="50%" align="right" valign="top"> |
54 |
+ |
<b><?php echo $title?></b> |
55 |
+ |
</td> |
56 |
+ |
<td width="50%" align="left" valign="top"> |
57 |
+ |
<?php if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) { |
58 |
+ |
linkToHistory($graph); |
59 |
+ |
} ?> |
60 |
+ |
<?php echo uptime($value)?> (<?php echo $value?> seconds)</td> |
61 |
+ |
</tr> |
62 |
+ |
</table> |
63 |
+ |
<?php |
64 |
+ |
} |
65 |
+ |
|
66 |
+ |
|
67 |
+ |
function showStat($title, $value, $input, $graph="") { |
68 |
+ |
|
69 |
|
$report = $value; |
70 |
|
|
71 |
|
$value = getPregMatch($value, $input); |
76 |
|
<table border="0" width="100%"> |
77 |
|
<tr> |
78 |
|
<td width="50%" align="right" valign="top"> |
79 |
< |
<b><?=$title?></b> |
79 |
> |
<b><?php echo $title?></b> |
80 |
|
</td> |
81 |
|
<td width="50%" align="left" valign="top"> |
82 |
< |
<? if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) { |
83 |
< |
linkToHistory($report); |
82 |
> |
<?php if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) { |
83 |
> |
linkToHistory($graph); |
84 |
|
} ?> |
85 |
< |
<?=$value?></td> |
85 |
> |
<?php echo $value?></td> |
86 |
|
</tr> |
87 |
|
</table> |
88 |
< |
<? |
88 |
> |
<?php |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
< |
function linkToHistory($report) { |
92 |
> |
function linkToHistory($graph) { |
93 |
|
global $machine; |
94 |
< |
$yesterday = date("Y-m-d", time() - 86400); |
95 |
< |
echo <<<EOT |
96 |
< |
<a href="browser.php?machine_name=$machine&report=$report&day=$yesterday&submit=Show"><img src="minichart.gif" alt="View yesterday's 24-hour chart" width="20" height="20" border="0"></a> |
94 |
> |
if(!empty($graph)) { |
95 |
> |
echo <<<EOT |
96 |
> |
<a href="graphs.php?machine_name=$machine&graph=$graph&submit=Show"><img src="minichart.gif" alt="View historical graphs of this data" width="20" height="20" border="0"></a> |
97 |
|
EOT; |
98 |
+ |
} |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
+ |
# convert bytes to MB |
103 |
+ |
function b2Mb($bytes) { |
104 |
+ |
$mb = $bytes / (1024*1024); |
105 |
+ |
return (int) $mb; |
106 |
+ |
} |
107 |
+ |
|
108 |
+ |
|
109 |
+ |
# Convert seconds uptime to something readable |
110 |
+ |
function uptime($until) { |
111 |
+ |
$day = date('z', $until); |
112 |
+ |
$hour = date('G', $until); |
113 |
+ |
if ($hour == 0) { # everything's an hour ahead, so roll back |
114 |
+ |
$hour = 23; |
115 |
+ |
$day = $day - 1; |
116 |
+ |
} else { |
117 |
+ |
$hour = $hour - 1; |
118 |
+ |
} |
119 |
+ |
$minute = date('i', $until); |
120 |
+ |
$return = ""; |
121 |
+ |
if ($day) { |
122 |
+ |
$return = "$return$day"; |
123 |
+ |
if ($day == 1) { |
124 |
+ |
$return = "$return Day "; |
125 |
+ |
} else { |
126 |
+ |
$return = "$return Days "; |
127 |
+ |
} |
128 |
+ |
} |
129 |
+ |
if ($hour) { |
130 |
+ |
$return = "$return$hour"; |
131 |
+ |
if ($hour == 1) { |
132 |
+ |
$return = "$return Hour "; |
133 |
+ |
} else { |
134 |
+ |
$return = "$return Hours "; |
135 |
+ |
} |
136 |
+ |
} |
137 |
+ |
$return = "$return$minute"; |
138 |
+ |
if ($minute == 1) { |
139 |
+ |
$return = "$return Min"; |
140 |
+ |
} else { |
141 |
+ |
$return = "$return Mins"; |
142 |
+ |
} |
143 |
+ |
return $return; |
144 |
+ |
} |
145 |
+ |
|
146 |
+ |
|
147 |
|
# show all disk information. |
148 |
|
function showDisks($diskRoot, $units, $input) { |
149 |
|
include("latest_config.inc.php"); |
154 |
|
$mount = getPregMatch("$diskRoot.p$i.attributes.mount", $input); |
155 |
|
if ($name || $mount) { |
156 |
|
$used = "$diskRoot.p$i.attributes.used"; |
157 |
< |
$kbytes = "$diskRoot.p$i.attributes.kbytes"; |
158 |
< |
showBar("$name<br>($mount)", $used, $kbytes, $units, $input); |
157 |
> |
$total = "$diskRoot.p$i.attributes.total"; |
158 |
> |
$graph = preg_replace("/_/", "$hex_underscore", $mount); |
159 |
> |
$graph = preg_replace("/\//", "$hex_slash", $graph); |
160 |
> |
$graph = preg_replace("/\\\\/", "$hex_bslash", $graph); |
161 |
> |
$graph = preg_replace("/ /", "$hex_space", $graph); |
162 |
> |
$graph = preg_replace("/:/", "$hex_colon", $graph); |
163 |
> |
$totalinodes = getPregMatch("$diskRoot.p$i.attributes.totalinodes", $input); |
164 |
> |
$freeinodes = getPregMatch("$diskRoot.p$i.attributes.freeinodes", $input); |
165 |
> |
showBar("$name ($mount)<br>space used", $used, $total, $units, $input, "disk-$graph"); |
166 |
> |
showBar("inodes used", (float) $freeinodes, (float) $totalinodes, " inodes", $input, "", "swap"); |
167 |
> |
showStat("FS Type", "$diskRoot.p$i.attributes.fstype", $input); |
168 |
> |
print " <br><br>\n"; |
169 |
|
} |
170 |
|
else { |
171 |
|
break; |
174 |
|
} |
175 |
|
} |
176 |
|
|
177 |
+ |
|
178 |
+ |
# show all disk IO information. |
179 |
+ |
function showDiskIO($diskRoot, $input) { |
180 |
+ |
include("latest_config.inc.php"); |
181 |
+ |
|
182 |
+ |
$i = 0; |
183 |
+ |
while(1) { |
184 |
+ |
$name = getPregMatch("$diskRoot.p$i.attributes.name", $input); |
185 |
+ |
if ($name) { |
186 |
+ |
$graph = preg_replace("/_/", "$hex_underscore", $name); |
187 |
+ |
$graph = preg_replace("/\//", "$hex_slash", $graph); |
188 |
+ |
$graph = preg_replace("/\\\\/", "$hex_bslash", $graph); |
189 |
+ |
$graph = preg_replace("/ /", "$hex_space", $graph); |
190 |
+ |
$graph = preg_replace("/:/", "$hex_colon", $graph); |
191 |
+ |
print "<br><center><b>(Disk $name)</b></center>"; |
192 |
+ |
showStat("Read bytes (per sec)", "$diskRoot.p$i.attributes.rbytes", $input, "diskio-$graph"); |
193 |
+ |
showStat("Write bytes (per sec)", "$diskRoot.p$i.attributes.wbytes", $input, "diskio-$graph"); |
194 |
+ |
print " <br>\n"; |
195 |
+ |
} |
196 |
+ |
else { |
197 |
+ |
break; |
198 |
+ |
} |
199 |
+ |
$i++; |
200 |
+ |
} |
201 |
+ |
} |
202 |
+ |
|
203 |
+ |
|
204 |
+ |
# show all network information. |
205 |
+ |
function showNet($netRoot, $input) { |
206 |
+ |
include("latest_config.inc.php"); |
207 |
+ |
|
208 |
+ |
$i = 0; |
209 |
+ |
while(1) { |
210 |
+ |
$name = getPregMatch("$netRoot.p$i.attributes.name", $input); |
211 |
+ |
if ($name) { |
212 |
+ |
$graph = preg_replace("/_/", "$hex_underscore", $name); |
213 |
+ |
$graph = preg_replace("/\//", "$hex_slash", $graph); |
214 |
+ |
$graph = preg_replace("/\\\\/", "$hex_bslash", $graph); |
215 |
+ |
$graph = preg_replace("/ /", "$hex_space", $graph); |
216 |
+ |
$graph = preg_replace("/:/", "$hex_colon", $graph); |
217 |
+ |
$graph = preg_replace("/\(/", "$hex_lbracket", $graph); |
218 |
+ |
$graph = preg_replace("/\)/", "$hex_rbracket", $graph); |
219 |
+ |
$graph = preg_replace("/\+/", "$hex_plus", $graph); |
220 |
+ |
$graph = preg_replace("/#/", "$hex_hash", $graph); |
221 |
+ |
print "<br><center><b>(Network Interface $name)</b></center>"; |
222 |
+ |
showStat("Received bytes (per sec)", "$netRoot.p$i.attributes.rx", $input, "net-$graph"); |
223 |
+ |
showStat("Transfered bytes (per sec)", "$netRoot.p$i.attributes.tx", $input, "net-$graph"); |
224 |
+ |
print " <br>\n"; |
225 |
+ |
} |
226 |
+ |
else { |
227 |
+ |
break; |
228 |
+ |
} |
229 |
+ |
$i++; |
230 |
+ |
} |
231 |
+ |
} |
232 |
+ |
|
233 |
+ |
|
234 |
+ |
# show all mail queue information |
235 |
+ |
function showMailQ($mailqRoot, $input) { |
236 |
+ |
include("latest_config.inc.php"); |
237 |
+ |
|
238 |
+ |
$i = 0; |
239 |
+ |
while(1) { |
240 |
+ |
$name = getPregMatch("$mailqRoot.p$i.attributes.name", $input); |
241 |
+ |
if ($name) { |
242 |
+ |
print "<br><center><b>($name)</b></center>"; |
243 |
+ |
$name = preg_replace("/\s+/", "", $name); |
244 |
+ |
showStat("Messages in queue", "$mailqRoot.p$i.attributes.size", $input, "mailq-$name"); |
245 |
+ |
print " <br>\n"; |
246 |
+ |
} |
247 |
+ |
else { |
248 |
+ |
break; |
249 |
+ |
} |
250 |
+ |
$i++; |
251 |
+ |
} |
252 |
+ |
} |
253 |
+ |
|
254 |
+ |
|
255 |
|
# Return a preg_match result. |
256 |
|
function getPregMatch($value, $input) { |
257 |
|
preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches); |
258 |
+ |
if(!isset($matches[1])) { |
259 |
+ |
return; |
260 |
+ |
} |
261 |
|
return $matches[1]; |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
|
# show a bar-represented value. |
266 |
< |
function showBar($title, $value, $max, $units, $input, $arrange='normal') { |
266 |
> |
function showBar($title, $value, $max, $units, $input, $graph="", $arrange='normal') { |
267 |
|
|
268 |
|
include("latest_config.inc.php"); |
269 |
|
|
270 |
|
$report = $value; |
271 |
< |
|
272 |
< |
$value = getPregMatch($value, $input); |
271 |
> |
if (!is_int($value)) { |
272 |
> |
$value = getPregMatch($value, $input); |
273 |
> |
} |
274 |
|
if (!is_int($max)) { |
275 |
|
$max = getPregMatch($max, $input); |
276 |
|
} |
282 |
|
$value = $max - $value; |
283 |
|
} |
284 |
|
|
285 |
+ |
if ($units == 'MB') { |
286 |
+ |
$value = b2Mb ($value); |
287 |
+ |
$max = b2Mb ($max); |
288 |
+ |
} |
289 |
+ |
|
290 |
|
if(empty($max)) { |
291 |
|
$width = 1; |
292 |
|
} |
300 |
|
?> |
301 |
|
<table border="0" cellpadding="0" cellspacing="0" align="center"> |
302 |
|
<tr> |
303 |
< |
<td colspan="2"><? linkToHistory($report); ?> <b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td> |
303 |
> |
<td colspan="2"><?php linkToHistory($graph); ?> <b><?php echo $title?></b> <font size="2">(<?php echo $value?><?php echo $units?>)</font></td> |
304 |
|
</tr> |
305 |
|
<tr> |
306 |
< |
<td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td> |
306 |
> |
<td colspan="2" bgcolor="#eeeeff"><img src="<?php echo $barImage?>" border="0" height="20" width="<?php echo $width?>"></td> |
307 |
|
</tr> |
308 |
|
<tr> |
309 |
< |
<td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td> |
309 |
> |
<td colspan="2"><img src="<?php echo $scaleImage?>" border="0" height="11" width="<?php echo $max_width?>"></td> |
310 |
|
</tr> |
311 |
|
<tr> |
312 |
< |
<td align="left">0<?=$units?></td> |
313 |
< |
<td align="right"><?=$max?><?=$units?></td> |
312 |
> |
<td align="left">0<?php echo $units?></td> |
313 |
> |
<td align="right"><?php echo $max?><?php echo $units?></td> |
314 |
|
</tr> |
146 |
– |
<tr> |
147 |
– |
<td colspan="2"> </td> |
148 |
– |
</tr> |
315 |
|
</table> |
316 |
< |
<? |
316 |
> |
<?php |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
|
?> |
321 |
|
|
322 |
< |
<? include($titleHTML); ?> |
322 |
> |
<?php include($titleHTML); ?> |
323 |
|
|
324 |
< |
<? printLine("Display the latest information received from a host"); ?> |
324 |
> |
<?php printLine("Display the latest information received from a host"); ?> |
325 |
|
|
326 |
< |
<form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> |
327 |
< |
<? |
326 |
> |
<form method="<?php echo $formMethod ?>" action="<?php echo $thisPage ?>"> |
327 |
> |
<?php |
328 |
|
|
329 |
|
$file_array = getdirArray($latestDirectory,'asort'); |
330 |
|
print "<select size=\"1\" name=\"machine\">"; |
331 |
|
if ($machine) { ?> |
332 |
< |
<option selected value="<? echo $machine ?>"><? echo $machine ?></option> |
332 |
> |
<option selected value="<?php echo $machine ?>"><?php echo $machine ?></option> |
333 |
|
<option value="">----------------</option> |
334 |
< |
<? } |
334 |
> |
<?php } |
335 |
|
foreach($file_array as $file_name) { |
336 |
|
#if (is_dir($file_name)) { |
337 |
|
print "<option value=\"$file_name\">$file_name</option>"; |
343 |
|
<input type="submit" name="submit" value="Display"> |
344 |
|
</form> |
345 |
|
|
346 |
< |
<? if ($machine) { |
346 |
> |
<?php if ($machine) { |
347 |
|
|
348 |
|
$last_modified = filemtime("$latestDirectory/$machine/$latestData"); |
349 |
|
clearstatcache(); |
360 |
|
This realtime report is too old to be considered recent |
361 |
|
EOT; |
362 |
|
} |
363 |
+ |
else { |
364 |
+ |
$warning = ""; |
365 |
+ |
} |
366 |
|
|
367 |
|
echo <<<EOT |
368 |
|
<table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1"> |
398 |
|
|
399 |
|
?> |
400 |
|
|
401 |
< |
<? printLine(""); ?> |
401 |
> |
<?php printLine(""); ?> |
402 |
|
|
403 |
< |
<? include($bottomHTML); ?> |
403 |
> |
<?php include($bottomHTML); ?> |