#443 new enhancement

95th percentile graphs

Reported by: anarcat Owned by: janl
Priority: high Milestone: Munin 3.0.0
Component: design Version:
Severity: normal Keywords:
Cc: anarcat@…


It would be nice to have a line that would calculate the "95th percentile" which is often used in billing. A good explanation and the original MRTG patch is now unavailable except in the web archive:


The idea is to cut off 5% of the peaks and compute the average traffic based on that. It is a more faithful way of billing than just charging the average.

A more recent patch to MRTG is here: http://www.macserve.net/software/mrtg95/

Is this possible in Munin? Asking for 1.6...

Attachments (3)

go.patch (1.4 KB) - added by insom at 2010-08-03T14:26:15+02:00.
Patch against 1.4.3 to add 95th
blue1.jpg (65.6 KB) - added by Slavon8 at 2015-02-09T20:02:36+01:00.
Bob Foster.jpg (32.0 KB) - added by Slavon8 at 2015-03-01T16:15:21+01:00.
Find out more about kidkraft espresso kitchens.

Download all attachments as: .zip

Change History (14)

comment:1 Changed at 2006-10-27T10:27:28+02:00 by janl

  • Severity changed from major to normal
  • Version 1.2.4 deleted

Shouldn't this be in rrd instead? To put it in munin would mean collecting the numbers into the rrd file and then writing a new rrd dataset from that --- and then graph the modified set?


comment:2 Changed at 2006-10-27T11:01:04+02:00 by janl

Looks sort of simple

  1. tune the origin rrd file to save 5 minute samples for 30 days
  2. run the 95 script to generate a new rrd file to plot from

There are some reservations about how well this will work at http://www.merit.edu/mail.archives/nanog/2001-04/msg00538.html

comment:3 Changed at 2007-09-25T21:13:27+02:00 by janl

  • Milestone changed from Munin 1.6 to Munin 1.4
  • Owner changed from nobody to janl
  • Priority changed from normal to high

comment:4 in reply to: ↑ description Changed at 2007-11-16T19:51:45+01:00 by mozai

For what it's worth, this Perl code will give you the N-th percentile for the sum of the fields in rrd file X. AFAIK, rrdtool doesn't calculate this number automatically; it's just a very popular feature of the many tools that use rrdtool for graphing.

use RRDs;

sub percentile($;$$) {
  my ($rrdfile,$duration,$n_th) = @_;
  # duration should be 1day, 1week, 1month or 1year.
  $duration ||= "1week";
  $n_th ||= 95; # can't have 0th percentile
  my ($start,$step,$names,$data) = RRDs::fetch($rrdfile,"MAX","-s","-$duration");
  my @sums = ();
  my $timestamp = $start;
  ROWLOOP: foreach my $row (@$data) {
    my $sum = 0;
    $timestamp += $step;
    foreach my $field (@$row) {
      next ROWLOOP if (! defined $field); # skip rows that have NaN
      $sum += $field;
  my $which = int(scalar(@sums)*($n_th)/100);
  @sums = sort{$a<=>$b}(@sums);  # sort defaults to alpha sorting of int? wtf?
  #debug# for (my $i=0; $i<=$#sums; $i++) {print"$sums[$i]".($i==$which?'<--':'')."\n"; }
  return $sums[$which];

# -- main()

my $nth = 95;
$rrdfile = '/var/www/html/cacti/rra/access_switch_c2950243_traffic_in_404.rrd';

print $nth."th percentile: ".&percentile($rrdfile,"1week",$nth) ."\n";
print "Consulting the last week's traffic on c2950-24-3\n";
print "(using rrd file $rrdfile)\n";

comment:5 Changed at 2008-10-20T17:52:53+02:00 by TTimo


is this still being worked on?

comment:6 Changed at 2008-10-22T01:26:30+02:00 by TTimo

The script provided on the ticket very likely works, I believe it's only approximate unless there is a RRA with 5 minute data and the script is modified to hit exactly only that data for the percentile computation. It is good enough for most cases.

However there is nothing setup for a plugin writer to request nth percentile on any of the data and have it drawn on the graph?

comment:7 Changed at 2008-12-05T15:35:59+01:00 by janl

Looks like making such a line is supported in rrd as examplified some way down in http://oss.oetiker.ch/rrdtool/doc/rrdgraph_examples.en.html. As my munins are down due to me moving house I need to generate some rrd files to experiment with

comment:8 Changed at 2009-10-27T23:45:18+01:00 by janl

  • Milestone changed from Munin 1.4 to Munin 1.5

This will not make it into 1.4

comment:9 Changed at 2009-12-04T23:20:26+01:00 by janl

And we need to rewrite munin-graph before attempting this. 1.5 or 1.6.

comment:10 Changed at 2010-01-18T13:06:02+01:00 by janl

  • Milestone changed from Munin 1.5 to Munin 1.6

Changed at 2010-08-03T14:26:15+02:00 by insom

Patch against 1.4.3 to add 95th

comment:11 Changed at 2010-08-03T14:27:33+02:00 by insom

I've attached a patch which uses VDEFs in rrdtool 1.2 to put a 95th marker on graphs. It's rough- it applies to the positive side of any single value graph. This is kind of useful, but more options and a graceful way to handle VDEFs would be better. This suits our needs, I thought I would share.

Changed at 2015-03-01T16:15:21+01:00 by Slavon8

Find out more about kidkraft espresso kitchens.

Note: See TracTickets for help on using tickets.