ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/reports/php/latest/latest.php
(Generate patch)

Comparing projects/cms/source/reports/php/latest/latest.php (file contents):
Revision 1.2 by pjm2, Thu Mar 8 21:40:45 2001 UTC vs.
Revision 1.49 by tdb, Wed May 4 14:14:25 2005 UTC

# Line 1 | Line 1
1   <?php
2  
3 # Navigation for the i-scream reports.
4 # pjm2@ukc.ac.uk
3   #
4 + # i-scream central monitoring system
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
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   # CONFIGURABLE CONSTANTS: -
24  
25   include("latest_config.inc.php");
# Line 10 | Line 27 | include("latest_config.inc.php");
27   #
28   # END CONFIGURATION
29  
30 + include("iutils.inc.php");
31  
32 < # return an array of subdirectories from a directory.
33 < function getdirArray($dir='./',$sort='asort') {
34 <    global $dir_file_count;
35 <    if ( is_dir($dir) ) {
36 <        $fd = @opendir($dir);
37 <        while ( ($part = @readdir($fd)) == TRUE ) {
38 <            clearstatcache();
39 <            if ($part != "." && $part != "..") {
40 <                $dir_array[] = $part;
41 <            }
42 <        }
43 <        if($fd == TRUE) {
44 <            closedir($fd);
45 <        }
46 <        if (is_array($dir_array)) {
47 <            $sort($dir_array);
48 <            $dir_file_count = count($dir_array);
31 <            Return $dir_array;
32 <        } else {
33 <            Return FALSE;
34 <        }
35 <    } else {
36 <        Return FALSE;
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) {
68 <    preg_match("/$value=([^\,]*)\,/", $input, $matches);
69 <    $value = $matches[1];
70 <    if (empty($value)) {
71 <        $value = "<i>unknown</i>";
67 > function showStat($title, $value, $input, $graph="") {
68 >
69 >    $report = $value;
70 >
71 >    $value = getPregMatch($value, $input);
72 >    if (!isset($value)) {
73 >        $value = "<i><font color=\"#999999\">not sent</font></i>";
74      }
75      ?>
76          <table border="0" width="100%">
77            <tr>
78 <            <td width="50%" align="right"><b><?=$title?></b></td>
79 <            <td width="50%" align="left"><?=$value?></td>
78 >            <td width="50%" align="right" valign="top">
79 >             <b><?=$title?></b>
80 >            </td>
81 >            <td width="50%" align="left" valign="top">
82 >             <? if (preg_match("/^[0-9]+\.?[0-9]*$/", $value)) {
83 >                    linkToHistory($graph);
84 >                } ?>
85 >              <?=$value?></td>
86            </tr>
87          </table>
88      <?
89   }
90  
91  
92 + function linkToHistory($graph) {
93 +    global $machine;
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");
150 +
151 +    $i = 0;
152 +    while(1) {
153 +        $name = getPregMatch("$diskRoot.p$i.attributes.name", $input);
154 +        $mount = getPregMatch("$diskRoot.p$i.attributes.mount", $input);
155 +        if ($name || $mount) {
156 +            $used = "$diskRoot.p$i.attributes.used";
157 +            $total = "$diskRoot.p$i.attributes.total";
158 +            $graph = preg_replace("/_/", "$hex_underscore", $mount);
159 +            $graph = preg_replace("/\//", "$hex_slash", $graph);
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", (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 {
168 +            break;
169 +        }
170 +        $i++;
171 +    }
172 + }
173 +
174 +
175 + # show all disk IO information.
176 + function showDiskIO($diskRoot, $input) {
177 +    include("latest_config.inc.php");
178 +
179 +    $i = 0;
180 +    while(1) {
181 +        $name = getPregMatch("$diskRoot.p$i.attributes.name", $input);
182 +        if ($name) {
183 +            print "<br><center><b>(Disk $name)</b></center>";
184 +            showStat("Read bytes (per sec)", "$diskRoot.p$i.attributes.rbytes", $input, "diskio-$name");
185 +            showStat("Write bytes (per sec)", "$diskRoot.p$i.attributes.wbytes", $input, "diskio-$name");
186 +            print "          <br>\n";
187 +        }
188 +        else {
189 +            break;
190 +        }
191 +        $i++;
192 +    }
193 + }
194 +
195 +
196 + # show all network information.
197 + function showNet($netRoot, $input) {
198 +    include("latest_config.inc.php");
199 +
200 +    $i = 0;
201 +    while(1) {
202 +        $name = getPregMatch("$netRoot.p$i.attributes.name", $input);
203 +        if ($name) {
204 +            print "<br><center><b>(Network Interface $name)</b></center>";
205 +            showStat("Received bytes (per sec)", "$netRoot.p$i.attributes.rx", $input, "net-$name");
206 +            showStat("Transfered bytes (per sec)", "$netRoot.p$i.attributes.tx", $input, "net-$name");
207 +            print "          <br>\n";
208 +        }
209 +        else {
210 +            break;
211 +        }
212 +        $i++;
213 +    }
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 +
247 +
248   # show a bar-represented value.
249 < function showBar($title, $value, $max, $input) {
249 > function showBar($title, $value, $max, $units, $input, $graph="", $arrange='normal') {
250  
251      include("latest_config.inc.php");
252  
253 <    preg_match("/$value=([^\,]*)\,/", $input, $matches);
254 <    $value = $matches[1];
253 >    $report = $value;
254 >    if (!is_int($value)) {
255 >        $value = getPregMatch($value, $input);
256 >    }
257      if (!is_int($max)) {
258 <        preg_match("/$max=([^\,]*)\,/", $input, $matches);
67 <        $max = $matches[1];
258 >        $max = getPregMatch($max, $input);
259      }
260 <    if (empty($value) || empty($max)) {
260 >    if (!isset($value) || !isset($max)) {
261          return;
262      }
263  
264 <    $width = intval($max_width * $value / $max);
264 >    if ($arrange == 'swap') {
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 +    }
276 +    else {
277 +        $width = intval($max_width * $value / $max);
278 +        if ($width < 1) {
279 +            $width = 1;
280 +        }
281 +    }
282 +
283      ?>
284 <        <table border="0" cellpadding="0" cellspacing="0">
284 >        <table border="0" cellpadding="0" cellspacing="0" align="center">
285            <tr>
286 <            <td colspan="2"><b><?=$title?></b></td>
286 >            <td colspan="2"><? linkToHistory($graph); ?> <b><?=$title?></b> <font size="2">(<?=$value?><?=$units?>)</font></td>
287            </tr>
288            <tr>
289              <td colspan="2" bgcolor="#eeeeff"><img src="<?=$barImage?>" border="0" height="20" width="<?=$width?>"></td>
# Line 84 | Line 292 | function showBar($title, $value, $max, $input) {
292              <td colspan="2"><img src="<?=$scaleImage?>" border="0" height="11" width="<?=$max_width?>"></td>
293            </tr>
294            <tr>
295 <            <td align="left">0</td>
296 <            <td align="right"><?=$max?></td>
295 >            <td align="left">0<?=$units?></td>
296 >            <td align="right"><?=$max?><?=$units?></td>
297            </tr>
298          </table>
299      <?
# Line 96 | Line 304 | function showBar($title, $value, $max, $input) {
304  
305   <? include($titleHTML); ?>
306  
307 < <hr weight="1" color="<? echo $lineColor ?>">
307 > <? printLine("Display the latest information received from a host"); ?>
308  
101 <b>Display the latest information received from a host</b>
309   <form method="<? echo $formMethod ?>" action="<? echo $thisPage ?>">
310   <?
311  
312 <    $file_array = getdirArray($latestDirectory,'rsort');
312 >    $file_array = getdirArray($latestDirectory,'asort');
313      print "<select size=\"1\" name=\"machine\">";
314      if ($machine) { ?>
315          <option selected value="<? echo $machine ?>"><? echo $machine ?></option>
316          <option value="">----------------</option>
317      <? }
318      foreach($file_array as $file_name) {
319 <        if (is_dir($file_name)) {
113 <            $i++;
319 >        #if (is_dir($file_name)) {
320              print "<option value=\"$file_name\">$file_name</option>";
321 <        }
321 >        #}
322      }
323      print "</select>";
324  
# Line 120 | Line 326 | function showBar($title, $value, $max, $input) {
326   <input type="submit" name="submit" value="Display">
327   </form>
328  
123 <hr weight="1" color="<? echo $lineColor ?>">
124
329   <? if ($machine) {
330  
331 +       $last_modified = filemtime("$latestDirectory/$machine/$latestData");
332 +       clearstatcache();
333 +       $data_age = time() - $last_modified;
334 +
335 +       $last_modified = date("l jS F Y - g:ia", $last_modified);
336 +
337 +       if ($data_age > $warning_age) {
338 +           $warning = <<<EOT
339 +               <br>
340 +               <font color="red"><b>
341 +                   Warning:
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
351 +       <table border="0" bgcolor="#000066" cellpadding="3" cellspacing="1">
352 +         <tr>
353 +           <td bgcolor="#000066">
354 +             &nbsp;
355 +           </td>
356 +           <td bgcolor="#ffffcc">
357 +             <font face="arial,sans-serif" size="2">
358 +               <b>Receipt date:</b> $last_modified
359 +               $warning
360 +             </font>
361 +           </td>
362 +         </tr>
363 +       </table>
364 + EOT;
365 +
366         # Read the file.
367 <       #$input = "packet.attributes.machine_name=raptor.ukc.ac.uk,packet.memory.free=10,packet.memory.total=100,";
368 <       $input = file("$latestDirectory/$machine/$latestData");
369 <       # All we need is the first line if there is more than one line.
370 <       $input = $input[0];
367 >       if (file_exists("$latestDirectory/$machine/$latestData")) {
368 >           $input = file("$latestDirectory/$machine/$latestData");
369 >           # All we need is the first line if there is more than one line.
370 >           $input = $input[0];
371 >       }
372  
373 <       if (empty($input)) {
374 <           echo "<br><br>There was an error reading from the latest packet received.  Please notify your i-scream server administrator.";
373 >       if (!isset($input)) {
374 >           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.";
375         }
376         else {
377             # Display the data specified in the display include.
# Line 141 | Line 381 | function showBar($title, $value, $max, $input) {
381  
382   ?>
383  
384 + <? printLine(""); ?>
385  
386   <? include($bottomHTML); ?>

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines