1 |
pjm2 |
1.1 |
<?php |
2 |
|
|
|
3 |
tdb |
1.37 |
# |
4 |
|
|
# i-scream central monitoring system |
5 |
tdb |
1.41 |
# http://www.i-scream.org.uk |
6 |
tdb |
1.37 |
# Copyright (C) 2000-2002 i-scream |
7 |
|
|
# |
8 |
|
|
# This program is free software; you can redistribute it and/or |
9 |
|
|
# modify it under the terms of the GNU General Public License |
10 |
|
|
# as published by the Free Software Foundation; either version 2 |
11 |
|
|
# of the License, or (at your option) any later version. |
12 |
|
|
# |
13 |
|
|
# This program is distributed in the hope that it will be useful, |
14 |
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
|
|
# GNU General Public License for more details. |
17 |
|
|
# |
18 |
|
|
# You should have received a copy of the GNU General Public License |
19 |
|
|
# along with this program; if not, write to the Free Software |
20 |
|
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 |
|
|
# |
22 |
|
|
|
23 |
pjm2 |
1.1 |
# Navigation for the i-scream reports. |
24 |
|
|
# pjm2@ukc.ac.uk |
25 |
|
|
# |
26 |
|
|
# CONFIGURABLE CONSTANTS: - |
27 |
|
|
|
28 |
|
|
include("latest_config.inc.php"); |
29 |
|
|
|
30 |
|
|
# |
31 |
|
|
# END CONFIGURATION |
32 |
|
|
|
33 |
pjm2 |
1.18 |
include("iutils.inc.php"); |
34 |
pjm2 |
1.1 |
|
35 |
pjm2 |
1.9 |
function printLine($title) { |
36 |
pjm2 |
1.19 |
echo "<hr style=\"color:#9999ff;\">"; |
37 |
pjm2 |
1.9 |
echo "<b>$title</b>"; |
38 |
pjm2 |
1.6 |
} |
39 |
|
|
|
40 |
pjm2 |
1.1 |
|
41 |
tdb |
1.42 |
function showStat($title, $value, $input, $graph="") { |
42 |
pjm2 |
1.24 |
|
43 |
|
|
$report = $value; |
44 |
|
|
|
45 |
pjm2 |
1.28 |
$value = getPregMatch($value, $input); |
46 |
tdb |
1.38 |
if (!isset($value)) { |
47 |
pjm2 |
1.8 |
$value = "<i><font color=\"#999999\">not sent</font></i>"; |
48 |
pjm2 |
1.1 |
} |
49 |
|
|
?> |
50 |
|
|
<table border="0" width="100%"> |
51 |
|
|
<tr> |
52 |
pjm2 |
1.24 |
<td width="50%" align="right" valign="top"> |
53 |
|
|
<b><?=$title?></b> |
54 |
|
|
</td> |
55 |
|
|
<td width="50%" align="left" valign="top"> |
56 |
|
|
<? if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) { |
57 |
tdb |
1.42 |
linkToHistory($graph); |
58 |
pjm2 |
1.24 |
} ?> |
59 |
|
|
<?=$value?></td> |
60 |
pjm2 |
1.1 |
</tr> |
61 |
|
|
</table> |
62 |
|
|
<? |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
|
66 |
tdb |
1.42 |
function linkToHistory($graph) { |
67 |
pjm2 |
1.20 |
global $machine; |
68 |
tdb |
1.42 |
if(!empty($graph)) { |
69 |
|
|
echo <<<EOT |
70 |
|
|
<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> |
71 |
pjm2 |
1.20 |
EOT; |
72 |
tdb |
1.42 |
} |
73 |
pjm2 |
1.20 |
} |
74 |
|
|
|
75 |
|
|
|
76 |
pjm2 |
1.28 |
# show all disk information. |
77 |
|
|
function showDisks($diskRoot, $units, $input) { |
78 |
|
|
include("latest_config.inc.php"); |
79 |
|
|
|
80 |
|
|
$i = 0; |
81 |
|
|
while(1) { |
82 |
|
|
$name = getPregMatch("$diskRoot.p$i.attributes.name", $input); |
83 |
pjm2 |
1.31 |
$mount = getPregMatch("$diskRoot.p$i.attributes.mount", $input); |
84 |
|
|
if ($name || $mount) { |
85 |
|
|
$used = "$diskRoot.p$i.attributes.used"; |
86 |
tdb |
1.44 |
$total = "$diskRoot.p$i.attributes.total"; |
87 |
tdb |
1.42 |
$graph = preg_replace("/_/", "$hex_underscore", $mount); |
88 |
|
|
$graph = preg_replace("/\//", "$hex_slash", $graph); |
89 |
tdb |
1.43 |
$totalinodes = getPregMatch("$diskRoot.p$i.attributes.totalinodes", $input); |
90 |
|
|
$freeinodes = getPregMatch("$diskRoot.p$i.attributes.freeinodes", $input); |
91 |
tdb |
1.44 |
showBar("$name ($mount)<br>space used", $used, $total, $units, $input, "disk-$graph"); |
92 |
tdb |
1.43 |
showBar("inodes used", (int) $freeinodes, (int) $totalinodes, " inodes", $input, "", "swap"); |
93 |
|
|
print " <br><br>\n"; |
94 |
pjm2 |
1.28 |
} |
95 |
pjm2 |
1.30 |
else { |
96 |
|
|
break; |
97 |
|
|
} |
98 |
pjm2 |
1.28 |
$i++; |
99 |
|
|
} |
100 |
|
|
} |
101 |
tdb |
1.44 |
|
102 |
|
|
|
103 |
|
|
# show all disk IO information. |
104 |
|
|
function showDiskIO($diskRoot, $input) { |
105 |
|
|
include("latest_config.inc.php"); |
106 |
|
|
|
107 |
|
|
$i = 0; |
108 |
|
|
while(1) { |
109 |
|
|
$name = getPregMatch("$diskRoot.p$i.attributes.name", $input); |
110 |
|
|
if ($name) { |
111 |
|
|
print "<br><center><b>(Disk $name)</b></center>"; |
112 |
|
|
showStat("Read bytes (per sec)", "$diskRoot.p$i.attributes.rbytes", $input, "diskio-$name"); |
113 |
|
|
showStat("Write bytes (per sec)", "$diskRoot.p$i.attributes.wbytes", $input, "diskio-$name"); |
114 |
|
|
print " <br>\n"; |
115 |
|
|
} |
116 |
|
|
else { |
117 |
|
|
break; |
118 |
|
|
} |
119 |
|
|
$i++; |
120 |
|
|
} |
121 |
|
|
} |
122 |
|
|
|
123 |
|
|
|
124 |
|
|
# show all network information. |
125 |
|
|
function showNet($netRoot, $input) { |
126 |
|
|
include("latest_config.inc.php"); |
127 |
|
|
|
128 |
|
|
$i = 0; |
129 |
|
|
while(1) { |
130 |
|
|
$name = getPregMatch("$netRoot.p$i.attributes.name", $input); |
131 |
|
|
if ($name) { |
132 |
|
|
print "<br><center><b>(Network Interface $name)</b></center>"; |
133 |
|
|
showStat("Received bytes (per sec)", "$netRoot.p$i.attributes.rx", $input, "net-$name"); |
134 |
|
|
showStat("Transfered bytes (per sec)", "$netRoot.p$i.attributes.tx", $input, "net-$name"); |
135 |
|
|
print " <br>\n"; |
136 |
|
|
} |
137 |
|
|
else { |
138 |
|
|
break; |
139 |
|
|
} |
140 |
|
|
$i++; |
141 |
|
|
} |
142 |
|
|
} |
143 |
|
|
|
144 |
pjm2 |
1.28 |
|
145 |
|
|
# Return a preg_match result. |
146 |
|
|
function getPregMatch($value, $input) { |
147 |
pjm2 |
1.29 |
preg_match("/$value=([^\,\}]*)[\,\}]/", $input, $matches); |
148 |
pjm2 |
1.28 |
return $matches[1]; |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
|
152 |
pjm2 |
1.1 |
# show a bar-represented value. |
153 |
tdb |
1.42 |
function showBar($title, $value, $max, $units, $input, $graph="", $arrange='normal') { |
154 |
pjm2 |
1.1 |
|
155 |
|
|
include("latest_config.inc.php"); |
156 |
|
|
|
157 |
pjm2 |
1.22 |
$report = $value; |
158 |
tdb |
1.43 |
if (!is_int($value)) { |
159 |
|
|
$value = getPregMatch($value, $input); |
160 |
|
|
} |
161 |
pjm2 |
1.1 |
if (!is_int($max)) { |
162 |
pjm2 |
1.28 |
$max = getPregMatch($max, $input); |
163 |
pjm2 |
1.1 |
} |
164 |
tdb |
1.40 |
if (!isset($value) || !isset($max)) { |
165 |
pjm2 |
1.1 |
return; |
166 |
|
|
} |
167 |
|
|
|
168 |
pjm2 |
1.26 |
if ($arrange == 'swap') { |
169 |
pjm2 |
1.27 |
$value = $max - $value; |
170 |
pjm2 |
1.26 |
} |
171 |
pjm2 |
1.27 |
|
172 |
tdb |
1.40 |
if(empty($max)) { |
173 |
pjm2 |
1.35 |
$width = 1; |
174 |
tdb |
1.40 |
} |
175 |
|
|
else { |
176 |
|
|
$width = intval($max_width * $value / $max); |
177 |
|
|
if ($width < 1) { |
178 |
|
|
$width = 1; |
179 |
|
|
} |
180 |
pjm2 |
1.35 |
} |
181 |
|
|
|
182 |
pjm2 |
1.1 |
?> |
183 |
pjm2 |
1.10 |
<table border="0" cellpadding="0" cellspacing="0" align="center"> |
184 |
pjm2 |
1.1 |
<tr> |
185 |
tdb |
1.42 |
<td colspan="2"><? linkToHistory($graph); ?> <b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td> |
186 |
pjm2 |
1.1 |
</tr> |
187 |
|
|
<tr> |
188 |
|
|
<td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td> |
189 |
|
|
</tr> |
190 |
|
|
<tr> |
191 |
|
|
<td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td> |
192 |
|
|
</tr> |
193 |
|
|
<tr> |
194 |
pjm2 |
1.13 |
<td align="left">0<?=$units?></td> |
195 |
|
|
<td align="right"><?=$max?><?=$units?></td> |
196 |
pjm2 |
1.15 |
</tr> |
197 |
pjm2 |
1.1 |
</table> |
198 |
|
|
<? |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
|
202 |
|
|
?> |
203 |
|
|
|
204 |
|
|
<? include($titleHTML); ?> |
205 |
|
|
|
206 |
pjm2 |
1.12 |
<? printLine("Display the latest information received from a host"); ?> |
207 |
pjm2 |
1.1 |
|
208 |
|
|
<form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>"> |
209 |
|
|
<? |
210 |
|
|
|
211 |
pjm2 |
1.5 |
$file_array = getdirArray($latestDirectory,'asort'); |
212 |
pjm2 |
1.1 |
print "<select size=\"1\" name=\"machine\">"; |
213 |
|
|
if ($machine) { ?> |
214 |
|
|
<option selected value="<? echo $machine ?>"><? echo $machine ?></option> |
215 |
|
|
<option value="">----------------</option> |
216 |
|
|
<? } |
217 |
|
|
foreach($file_array as $file_name) { |
218 |
pjm2 |
1.3 |
#if (is_dir($file_name)) { |
219 |
pjm2 |
1.1 |
print "<option value=\"$file_name\">$file_name</option>"; |
220 |
pjm2 |
1.3 |
#} |
221 |
pjm2 |
1.1 |
} |
222 |
|
|
print "</select>"; |
223 |
|
|
|
224 |
|
|
?> |
225 |
|
|
<input type="submit" name="submit" value="Display"> |
226 |
|
|
</form> |
227 |
|
|
|
228 |
|
|
<? if ($machine) { |
229 |
|
|
|
230 |
pjm2 |
1.12 |
$last_modified = filemtime("$latestDirectory/$machine/$latestData"); |
231 |
|
|
clearstatcache(); |
232 |
|
|
$data_age = time() - $last_modified; |
233 |
|
|
|
234 |
pjm2 |
1.36 |
$last_modified = date("l jS F Y - g:ia", $last_modified); |
235 |
pjm2 |
1.12 |
|
236 |
|
|
if ($data_age > $warning_age) { |
237 |
|
|
$warning = <<<EOT |
238 |
|
|
<br> |
239 |
|
|
<font color="red"><b> |
240 |
|
|
Warning: |
241 |
|
|
</b></font> |
242 |
|
|
This realtime report is too old to be considered recent |
243 |
|
|
EOT; |
244 |
|
|
} |
245 |
|
|
|
246 |
|
|
echo <<<EOT |
247 |
pjm2 |
1.16 |
<table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1"> |
248 |
pjm2 |
1.12 |
<tr> |
249 |
|
|
<td bgcolor="#000066"> |
250 |
|
|
|
251 |
|
|
</td> |
252 |
|
|
<td bgcolor="#ffffcc"> |
253 |
|
|
<font face="arial,sans-serif" size="2"> |
254 |
pjm2 |
1.24 |
<b>Receipt date:</b> $last_modified |
255 |
pjm2 |
1.12 |
$warning |
256 |
|
|
</font> |
257 |
|
|
</td> |
258 |
|
|
</tr> |
259 |
|
|
</table> |
260 |
|
|
EOT; |
261 |
|
|
|
262 |
pjm2 |
1.1 |
# Read the file. |
263 |
pjm2 |
1.25 |
if (file_exists("$latestDirectory/$machine/$latestData")) { |
264 |
|
|
$input = file("$latestDirectory/$machine/$latestData"); |
265 |
|
|
# All we need is the first line if there is more than one line. |
266 |
|
|
$input = $input[0]; |
267 |
|
|
} |
268 |
pjm2 |
1.1 |
|
269 |
tdb |
1.38 |
if (!isset($input)) { |
270 |
pjm2 |
1.25 |
echo "<br><br>There are currently no latest details about <b>$machine</b>. Please notify your i-scream server administrator if you believe this to be incorrect."; |
271 |
pjm2 |
1.1 |
} |
272 |
|
|
else { |
273 |
|
|
# Display the data specified in the display include. |
274 |
|
|
include("latest_display.inc.php"); |
275 |
|
|
} |
276 |
pjm2 |
1.9 |
} |
277 |
pjm2 |
1.12 |
|
278 |
pjm2 |
1.1 |
?> |
279 |
|
|
|
280 |
pjm2 |
1.16 |
<? printLine(""); ?> |
281 |
pjm2 |
1.1 |
|
282 |
|
|
<? include($bottomHTML); ?> |