From 5f6b7410cb711fa6226f976e65aebd42049965f8 Mon Sep 17 00:00:00 2001 From: Manuel CISSÉ Date: Mon, 21 Jun 2010 13:49:36 +0200 Subject: Uptime plugin now display current/max/avg values in days instead of seconds --- plugin/uptime.php | 10 ++++---- type/Uptime.class.php | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 type/Uptime.class.php 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 @@ # Collectd Uptime plugin require_once 'conf/common.inc.php'; -require_once 'type/GenericStacked.class.php'; +require_once 'type/Uptime.class.php'; require_once 'inc/collectd.inc.php'; ## LAYOUT # uptime/uptime.rrd -$obj = new Type_GenericStacked($CONFIG); +$obj = new Type_Uptime($CONFIG); $obj->data_sources = array('value'); $obj->ds_names = array( - 'value' => 'seconds', + 'value' => 'Current', ); $obj->colors = array( - 'value' => '0000f0', + 'value' => '00e000', ); $obj->width = $width; $obj->heigth = $heigth; $obj->rrd_title = 'Uptime'; -$obj->rrd_vertical = 'Seconds'; +$obj->rrd_vertical = 'Days'; $obj->rrd_format = '%.1lf'; 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 @@ +rrd_options(); + + $sources = $this->rrd_get_sources(); + + $i=0; + foreach ($this->tinstances as $tinstance) { + foreach ($this->data_sources as $ds) { + $rrdgraph[] = sprintf('DEF:avg_%s=%s:%s:AVERAGE', crc32hex($sources[$i]), $this->files[$tinstance], $ds); + $rrdgraph[] = sprintf('DEF:max_%s=%s:%s:MAX', crc32hex($sources[$i]), $this->files[$tinstance], $ds); + + $rrdgraph[] = sprintf('CDEF:c_avg_%s=avg_%1$s,86400,/', crc32hex($sources[$i])); + $rrdgraph[] = sprintf('CDEF:c_max_%s=max_%1$s,86400,/', crc32hex($sources[$i])); + + $rrdgraph[] = sprintf('VDEF:v_avg_%s=c_avg_%1$s,AVERAGE', crc32hex($sources[$i])); + $rrdgraph[] = sprintf('VDEF:v_max_%s=c_max_%1$s,MAXIMUM', crc32hex($sources[$i])); + + $i++; + } + } + + for ($i=count($sources)-1 ; $i>=0 ; $i--) { + if ($i == (count($sources)-1)) + $rrdgraph[] = sprintf('CDEF:area_%s=c_avg_%1$s', crc32hex($sources[$i])); + else + $rrdgraph[] = sprintf('CDEF:area_%s=area_%s,c_avg_%1$s,+', crc32hex($sources[$i]), crc32hex($sources[$i+1])); + } + + $c = 0; + foreach ($sources as $source) { + $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; + $color = $this->get_faded_color($color); + $rrdgraph[] = sprintf('AREA:area_%s#%s', crc32hex($source), $color); + } + + $c = 0; + foreach ($sources as $source) { + $dsname = $this->ds_names[$source] != '' ? $this->ds_names[$source] : $source; + $color = is_array($this->colors) ? (isset($this->colors[$source])?$this->colors[$source]:$this->colors[$c++]) : $this->colors; + + //current value + $rrdgraph[] = sprintf('LINE1:area_%s#%s:\'%s\'', crc32hex($source), $this->validate_color($color), $dsname); + $rrdgraph[] = sprintf('GPRINT:c_avg_%s:LAST:\'%s days\\l\'', crc32hex($source), $this->rrd_format); + + //max value + $rrdgraph[] = sprintf('LINE1:v_max_%s#FF0000:\'Maximum\':dashes', crc32hex($source)); + $rrdgraph[] = sprintf('GPRINT:v_max_%s:\'%s days\\l\'', crc32hex($source), $this->rrd_format); + + //avg value + $rrdgraph[] = sprintf('LINE1:v_avg_%s#0000FF:\'Average\':dashes', crc32hex($source)); + $rrdgraph[] = sprintf('GPRINT:v_avg_%s:\'%s days\\l\'', crc32hex($source), $this->rrd_format); + } + + return $rrdgraph; + } +} + +?> -- cgit v1.1