diff options
| author | Manuel CISSÉ | 2010-06-21 13:49:36 +0200 |
|---|---|---|
| committer | Pim van den Berg | 2010-06-22 20:13:57 +0200 |
| commit | 5f6b7410cb711fa6226f976e65aebd42049965f8 (patch) | |
| tree | ac9ec3fd9ade81c0cb93dfba5f5d3fec58ced9db | |
| parent | remove php gd dependency (diff) | |
| download | apt-panopticon_cgp-5f6b7410cb711fa6226f976e65aebd42049965f8.zip apt-panopticon_cgp-5f6b7410cb711fa6226f976e65aebd42049965f8.tar.gz apt-panopticon_cgp-5f6b7410cb711fa6226f976e65aebd42049965f8.tar.bz2 apt-panopticon_cgp-5f6b7410cb711fa6226f976e65aebd42049965f8.tar.xz | |
Uptime plugin now display current/max/avg values in days instead of seconds
Diffstat (limited to '')
| -rw-r--r-- | plugin/uptime.php | 10 | ||||
| -rw-r--r-- | type/Uptime.class.php | 64 |
2 files changed, 69 insertions, 5 deletions
diff --git a/plugin/uptime.php b/plugin/uptime.php index 4c7db39..0d3d617 100644 --- a/plugin/uptime.php +++ b/plugin/uptime.php | |||
| @@ -3,24 +3,24 @@ | |||
| 3 | # Collectd Uptime plugin | 3 | # Collectd Uptime plugin |
| 4 | 4 | ||
| 5 | require_once 'conf/common.inc.php'; | 5 | require_once 'conf/common.inc.php'; |
| 6 | require_once 'type/GenericStacked.class.php'; | 6 | require_once 'type/Uptime.class.php'; |
| 7 | require_once 'inc/collectd.inc.php'; | 7 | require_once 'inc/collectd.inc.php'; |
| 8 | 8 | ||
| 9 | ## LAYOUT | 9 | ## LAYOUT |
| 10 | # uptime/uptime.rrd | 10 | # uptime/uptime.rrd |
| 11 | 11 | ||
| 12 | $obj = new Type_GenericStacked($CONFIG); | 12 | $obj = new Type_Uptime($CONFIG); |
| 13 | $obj->data_sources = array('value'); | 13 | $obj->data_sources = array('value'); |
| 14 | $obj->ds_names = array( | 14 | $obj->ds_names = array( |
| 15 | 'value' => 'seconds', | 15 | 'value' => 'Current', |
| 16 | ); | 16 | ); |
| 17 | $obj->colors = array( | 17 | $obj->colors = array( |
| 18 | 'value' => '0000f0', | 18 | 'value' => '00e000', |
| 19 | ); | 19 | ); |
| 20 | $obj->width = $width; | 20 | $obj->width = $width; |
| 21 | $obj->heigth = $heigth; | 21 | $obj->heigth = $heigth; |
| 22 | $obj->rrd_title = 'Uptime'; | 22 | $obj->rrd_title = 'Uptime'; |
| 23 | $obj->rrd_vertical = 'Seconds'; | 23 | $obj->rrd_vertical = 'Days'; |
| 24 | $obj->rrd_format = '%.1lf'; | 24 | $obj->rrd_format = '%.1lf'; |
| 25 | 25 | ||
| 26 | collectd_flush($obj->identifiers); | 26 | collectd_flush($obj->identifiers); |
diff --git a/type/Uptime.class.php b/type/Uptime.class.php new file mode 100644 index 0000000..04033a9 --- /dev/null +++ b/type/Uptime.class.php | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | <?php | ||
| 2 | |||
| 3 | require_once 'Default.class.php'; | ||
| 4 | |||
| 5 | class Type_Uptime extends Type_Default { | ||
| 6 | |||
| 7 | function rrd_gen_graph() { | ||
| 8 | $rrdgraph = $this->rrd_options(); | ||
| 9 | |||
| 10 | $sources = $this->rrd_get_sources(); | ||
| 11 | |||
| 12 | $i=0; | ||
| 13 | foreach ($this->tinstances as $tinstance) { | ||
| 14 | foreach ($this->data_sources as $ds) { | ||
| 15 | $rrdgraph[] = sprintf('DEF:avg_%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $this->files[$tinstance], $ds); | ||
| 16 | $rrdgraph[] = sprintf('DEF:max_%s=%s:%s:MAX', crc32hex($sources[$i]), $this->files[$tinstance], $ds); | ||
| 17 | |||
| 18 | $rrdgraph[] = sprintf('CDEF:c_avg_%s=avg_%1$s,86400,/', crc32hex($sources[$i])); | ||
| 19 | $rrdgraph[] = sprintf('CDEF:c_max_%s=max_%1$s,86400,/', crc32hex($sources[$i])); | ||
| 20 | |||
| 21 | $rrdgraph[] = sprintf('VDEF:v_avg_%s=c_avg_%1$s,AVERAGE', crc32hex($sources[$i])); | ||
| 22 | $rrdgraph[] = sprintf('VDEF:v_max_%s=c_max_%1$s,MAXIMUM', crc32hex($sources[$i])); | ||
| 23 | |||
| 24 | $i++; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | for ($i=count($sources)-1 ; $i>=0 ; $i--) { | ||
| 29 | if ($i == (count($sources)-1)) | ||
| 30 | $rrdgraph[] = sprintf('CDEF:area_%s=c_avg_%1$s', crc32hex($sources[$i])); | ||
| 31 | else | ||
| 32 | $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,c_avg_%1$s,+', crc32hex($sources[$i]), crc32hex($sources[$i+1])); | ||
| 33 | } | ||
| 34 | |||
| 35 | $c = 0; | ||
| 36 | foreach ($sources as $source) { | ||
| 37 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; | ||
| 38 | $color = $this->get_faded_color($color); | ||
| 39 | $rrdgraph[] = sprintf('AREA:area_%s#%s', crc32hex($source), $color); | ||
| 40 | } | ||
| 41 | |||
| 42 | $c = 0; | ||
| 43 | foreach ($sources as $source) { | ||
| 44 | $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; | ||
| 45 | $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; | ||
| 46 | |||
| 47 | //current value | ||
| 48 | $rrdgraph[] = sprintf('LINE1:area_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $dsname); | ||
| 49 | $rrdgraph[] = sprintf('GPRINT:c_avg_%s:LAST:\'%s days\\l\'', crc32hex($source), $this->rrd_format); | ||
| 50 | |||
| 51 | //max value | ||
| 52 | $rrdgraph[] = sprintf('LINE1:v_max_%s#FF0000:\'Maximum\':dashes', crc32hex($source)); | ||
| 53 | $rrdgraph[] = sprintf('GPRINT:v_max_%s:\'%s days\\l\'', crc32hex($source), $this->rrd_format); | ||
| 54 | |||
| 55 | //avg value | ||
| 56 | $rrdgraph[] = sprintf('LINE1:v_avg_%s#0000FF:\'Average\':dashes', crc32hex($source)); | ||
| 57 | $rrdgraph[] = sprintf('GPRINT:v_avg_%s:\'%s days\\l\'', crc32hex($source), $this->rrd_format); | ||
| 58 | } | ||
| 59 | |||
| 60 | return $rrdgraph; | ||
| 61 | } | ||
| 62 | } | ||
| 63 | |||
| 64 | ?> | ||
