From d21f4a765b82e4c02ff15bf730b0e1f0d68d5471 Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Tue, 24 Jun 2014 12:38:10 +0200 Subject: add percentile support to network traffic graphs Set $CONFIG['percentile'] to a number and a XXth percentile line + legend will be added to all network traffic (if_octets) graphs. Closes #81 --- conf/config.php | 4 ++++ graph.php | 3 +++ type/Base.class.php | 1 + type/GenericIO.class.php | 11 +++++++++++ 4 files changed, 19 insertions(+) diff --git a/conf/config.php b/conf/config.php index b086455..3d54e26 100644 --- a/conf/config.php +++ b/conf/config.php @@ -55,6 +55,10 @@ $CONFIG['rrd_fetch_method'] = 'sync'; # use the negative X-axis in I/O graphs $CONFIG['negative_io'] = false; +# add XXth percentile line + legend to network graphs +# false = disabled; 95 = 95th percentile +$CONFIG['percentile'] = false; + # create smooth graphs (rrdtool -E) $CONFIG['graph_smooth'] = false; diff --git a/graph.php b/graph.php index 55be9e9..dadb2c5 100644 --- a/graph.php +++ b/graph.php @@ -92,6 +92,9 @@ if (isset($plugin_json[$type]['rrdtool_opts'])) { if (isset($plugin_json[$type]['datasize']) and $plugin_json[$type]['datasize']) $obj->scale = $CONFIG['network_datasize'] == 'bits' ? 8 : 1; +if ($type == 'if_octets') + $obj->percentile = $CONFIG['percentile']; + if (isset($plugin_json[$type]['scale'])) $obj->scale = $plugin_json[$type]['scale']; diff --git a/type/Base.class.php b/type/Base.class.php index 40f3df0..883c98f 100644 --- a/type/Base.class.php +++ b/type/Base.class.php @@ -22,6 +22,7 @@ class Type_Base { var $height; var $graph_type; var $negative_io; + var $percentile = false; var $graph_smooth; var $files; diff --git a/type/GenericIO.class.php b/type/GenericIO.class.php index fac7034..a9d58cd 100644 --- a/type/GenericIO.class.php +++ b/type/GenericIO.class.php @@ -33,6 +33,8 @@ class Type_GenericIO extends Type_Base { if ($i == 1) $rrdgraph[] = sprintf('CDEF:avg_%s_neg=avg_%1$s_raw,%s%s,*', crc32hex($sources[$i]), $this->negative_io ? '-' : '', $this->scale); $rrdgraph[] = sprintf('VDEF:tot_%1$s=avg_%1$s,TOTAL', crc32hex($sources[$i])); + if ($this->percentile) + $rrdgraph[] = sprintf('VDEF:pct_%1$s=avg_%1$s_raw,%2$s,PERCENT', crc32hex($sources[$i]), $this->percentile); $i++; } } @@ -66,6 +68,15 @@ class Type_GenericIO extends Type_Base { $i++; } + if ($this->percentile) { + $rrdgraph[] = sprintf('"COMMENT: \l"'); + foreach($sources as $source) { + $legend = empty($this->legend[$source]) ? $source : $this->legend[$source]; + $rrdgraph[] = sprintf('"HRULE:pct_%s#%s:%sth Percentile %s"', crc32hex($source), $this->get_faded_color($this->colors[$source], '000000', 0.6), $this->percentile, $this->rrd_escape($legend)); + $rrdgraph[] = sprintf('"GPRINT:pct_%s:%s\l"', crc32hex($source), $this->rrd_format); + } + } + return $rrdgraph; } } -- cgit v1.1