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 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><?=$title?></b> |
55 |
+ |
</td> |
56 |
+ |
<td width="50%" align="left" valign="top"> |
57 |
+ |
<? if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) { |
58 |
+ |
linkToHistory($graph); |
59 |
+ |
} ?> |
60 |
+ |
<?=uptime($value)?> (<?=$value?> seconds)</td> |
61 |
+ |
</tr> |
62 |
+ |
</table> |
63 |
+ |
<? |
64 |
+ |
} |
65 |
+ |
|
66 |
+ |
|
67 |
|
function showStat($title, $value, $input, $graph="") { |
68 |
|
|
69 |
|
$report = $value; |
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"); |
160 |
|
$totalinodes = getPregMatch("$diskRoot.p$i.attributes.totalinodes", $input); |
161 |
|
$freeinodes = getPregMatch("$diskRoot.p$i.attributes.freeinodes", $input); |
162 |
|
showBar("$name ($mount)<br>space used", $used, $total, $units, $input, "disk-$graph"); |
163 |
< |
showBar("inodes used", (int) $freeinodes, (int) $totalinodes, " inodes", $input, "", "swap"); |
163 |
> |
showBar("inodes used", (float) $freeinodes, (float) $totalinodes, " inodes", $input, "", "swap"); |
164 |
> |
showStat("FS Type", "$diskRoot.p$i.attributes.fstype", $input); |
165 |
|
print " <br><br>\n"; |
166 |
|
} |
167 |
|
else { |
196 |
|
# show all network information. |
197 |
|
function showNet($netRoot, $input) { |
198 |
|
include("latest_config.inc.php"); |
199 |
< |
|
199 |
> |
|
200 |
|
$i = 0; |
201 |
|
while(1) { |
202 |
|
$name = getPregMatch("$netRoot.p$i.attributes.name", $input); |
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
+ |
# show all mail queue information |
218 |
+ |
function showMailQ($mailqRoot, $input) { |
219 |
+ |
include("latest_config.inc.php"); |
220 |
+ |
|
221 |
+ |
$i = 0; |
222 |
+ |
while(1) { |
223 |
+ |
$name = getPregMatch("$mailqRoot.p$i.attributes.name", $input); |
224 |
+ |
if ($name) { |
225 |
+ |
print "<br><center><b>($name)</b></center>"; |
226 |
+ |
$name = preg_replace("/\s+/", "", $name); |
227 |
+ |
showStat("Messages in queue", "$mailqRoot.p$i.attributes.size", $input, "mailq-$name"); |
228 |
+ |
print " <br>\n"; |
229 |
+ |
} |
230 |
+ |
else { |
231 |
+ |
break; |
232 |
+ |
} |
233 |
+ |
$i++; |
234 |
+ |
} |
235 |
+ |
} |
236 |
+ |
|
237 |
+ |
|
238 |
|
# Return a preg_match result. |
239 |
|
function getPregMatch($value, $input) { |
240 |
|
preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches); |
241 |
+ |
if(!isset($matches[1])) { |
242 |
+ |
return; |
243 |
+ |
} |
244 |
|
return $matches[1]; |
245 |
|
} |
246 |
|
|
265 |
|
$value = $max - $value; |
266 |
|
} |
267 |
|
|
268 |
+ |
if ($units == 'MB') { |
269 |
+ |
$value = b2Mb ($value); |
270 |
+ |
$max = b2Mb ($max); |
271 |
+ |
} |
272 |
+ |
|
273 |
|
if(empty($max)) { |
274 |
|
$width = 1; |
275 |
|
} |
342 |
|
</b></font> |
343 |
|
This realtime report is too old to be considered recent |
344 |
|
EOT; |
345 |
+ |
} |
346 |
+ |
else { |
347 |
+ |
$warning = ""; |
348 |
|
} |
349 |
|
|
350 |
|
echo <<<EOT |