Skip to content

Commit

Permalink
add percentile support to network traffic graphs
Browse files Browse the repository at this point in the history
Set $CONFIG['percentile'] to a number and a XXth percentile line + legend
will be added to all network traffic (if_octets) graphs.

Closes #81
  • Loading branch information
pommi committed Jun 24, 2014
1 parent 5da7a48 commit d21f4a7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conf/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
# 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;

Expand Down
3 changes: 3 additions & 0 deletions graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
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'];

Expand Down
1 change: 1 addition & 0 deletions type/Base.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Type_Base {
var $height;
var $graph_type;
var $negative_io;
var $percentile = false;
var $graph_smooth;

var $files;
Expand Down
11 changes: 11 additions & 0 deletions type/GenericIO.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ function rrd_gen_graph() {
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++;
}
}
Expand Down Expand Up @@ -66,6 +68,15 @@ function rrd_gen_graph() {
$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;
}
}
Expand Down

0 comments on commit d21f4a7

Please sign in to comment.