[42] | 1 | <?php |
---|
| 2 | /* |
---|
| 3 | (c)2006 Joe Presbrey <presbrey@mit.edu> |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | include('rrdgraph.inc.php'); |
---|
| 7 | require_once('rrdgraph.lib.php'); |
---|
| 8 | |
---|
| 9 | if (isset($_GET['h'])&&isset($_GET['s'])&&isset($_GET['i'])) { |
---|
| 10 | displayGraph($_GET['h'],$_GET['s'],$_GET['i']); |
---|
| 11 | exit; |
---|
| 12 | } |
---|
| 13 | |
---|
| 14 | $skip_host[] = 'localhost'; |
---|
| 15 | $skip_service[] = 'DISK_%2Fafs'; |
---|
| 16 | $skip_service[] = 'DISK_%2Fboot'; |
---|
| 17 | $skip_service[] = 'DISK_%2Fdev%2Fshm'; |
---|
| 18 | $only_host = array(); |
---|
| 19 | if (isset($_GET['host'])) |
---|
| 20 | $only_host[] = $_GET['host']; |
---|
| 21 | $only_service = array(); |
---|
| 22 | if (isset($_GET['service'])) |
---|
| 23 | $only_service[] = $_GET['service']; |
---|
| 24 | |
---|
| 25 | function getServices($time=115200) { |
---|
| 26 | $s = array(); |
---|
| 27 | foreach(glob("{$GLOBALS['RRD_PATH']}/*.rrd") as $f) { |
---|
| 28 | if (time()-filemtime($f)<=$time) { |
---|
| 29 | $e = explode('_', basename($f)); |
---|
| 30 | // //$s[$e[0]][] = $e[1]; |
---|
| 31 | if ($e[1] == 'DISK') |
---|
| 32 | $s[array_shift($e)][] = substr(implode('_', $e),0,-4); |
---|
| 33 | else { |
---|
| 34 | // array_pop($e); |
---|
| 35 | $s[$e[0]][] = $e[1]; |
---|
| 36 | } |
---|
| 37 | } |
---|
| 38 | } |
---|
| 39 | return $s; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | function displayGraph($host,$service,$time=null) { |
---|
| 43 | $times = array( |
---|
| 44 | 'hour' => 19200, |
---|
| 45 | 'day' => 115200, |
---|
| 46 | 'week' => 691200, |
---|
| 47 | 'month' => 3024000, |
---|
| 48 | 'year' => 34560000); |
---|
| 49 | $geom = array( |
---|
| 50 | 'hour' => '450x180', |
---|
| 51 | 'day' => '300x100', |
---|
| 52 | 'week' => '300x100', |
---|
| 53 | 'month' => '300x100', |
---|
| 54 | 'year' => '300x100'); |
---|
| 55 | $title = array( |
---|
| 56 | 'hour' => "$host: $service", |
---|
| 57 | 'day' => "$service today", |
---|
| 58 | 'week' => "$service this week", |
---|
| 59 | 'month' => "$service this month", |
---|
| 60 | 'year' => "$service this year"); |
---|
| 61 | if (is_null($time) || !isset($times[$time])) $time = 'day'; |
---|
| 62 | outputGraph($host, $service, $times[$time], array('legend'=>($time!='hour'?false:true), |
---|
| 63 | 'title'=>$title[$time], |
---|
| 64 | 'geom'=>explode('x',$geom[$time]))); |
---|
| 65 | //virtual('/ng/cgi-bin/show.cgi?host='.$host.'&service='.$service.'&graph='.$times[$time].'&geom='.$geom[$time].'&rrdopts='.str_replace(' ','_',$rrdopts[$time])); |
---|
| 66 | //virtual('/ng/cgi-rin/show.cgi?host='.$host.'&service='.$service.'&graph=118800'); |
---|
| 67 | //virtual('/ng/cgi-bin/show.cgi?host=better-mousetrap&service=LOAD&db=load&graph=118800'); |
---|
| 68 | exit; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | //displayGraph('better-mousetrap','LOAD'); |
---|
| 72 | echo '<table border=0 cellspacing=0 cellpadding=0>'; |
---|
| 73 | foreach(getServices() as $host=>$services) { |
---|
| 74 | $host = urldecode($host); |
---|
| 75 | if (in_array($host, $skip_host)) continue; |
---|
| 76 | if (count($only_host) && !in_array($host, $only_host)) continue; |
---|
| 77 | echo '<tr>'; |
---|
| 78 | foreach($services as $service) { |
---|
| 79 | if (in_array($service, $skip_service)) continue; |
---|
| 80 | if (count($only_service) && !in_array($service, $only_service)) continue; |
---|
| 81 | echo '<td>'; |
---|
| 82 | printf('<img src="show.php?h=%s&s=%s&i=%s">', $host, $service, 'hour'); |
---|
| 83 | echo '</td><td>'; |
---|
| 84 | printf('<img src="?h=%s&s=%s&i=%s">', $host, $service, 'day'); |
---|
| 85 | echo '<br />'; |
---|
| 86 | printf('<img src="?h=%s&s=%s&i=%s">', $host, $service, 'week'); |
---|
| 87 | echo '</td>'; |
---|
| 88 | } |
---|
| 89 | echo '</tr>'; |
---|
| 90 | } |
---|
| 91 | echo '</table>'; |
---|