# Ninety-Fifth Percentile Calculation for Bandwidth

I am trying to calculate the bandwidth of my current internet connection. I am pulling the current input and output transfer rate via snmp. If the argument to the following function is a sorted ascending list of the the some of each input and output sample, is this the right way to calculate 95th percentile?

sub ninetyFifth {
#Expects Sorted Data
my \$ninetyFifthLine = (@_ * .95) - 1;
return \$_[\$ninetyFifthLine];
}
-
The perl funkyness is that @_ is the number of items in the list, and that if the index of the array is float it just truncates (rounds down), and as I write this I think I just realized I don't need the - 1 ... – Kyle Brandt Mar 16 '10 at 11:57
Oh and as I read (en.wikipedia.org/wiki/Burstable_billing#95th_Percentile) this may not be right because I am taking a sample every 10 seconds, so maybe I should convert those samples into 5 minutes averages and then sum those averages, and then takes the 95th? – Kyle Brandt Mar 16 '10 at 12:00

## 1 Answer

Usually, the value grabbed via SNMP is "total octets sent/received since last interface counter clear", so unless you've post-processed it to get the "data sent during interval", you'll just end up with "data sent during the first 95% of samples". Though you say "transfer rate", so that should be OK (although if it is the same as is displayed on the show interface information on a Cisco router, it's not actual throughput, it's the exponential average of short-period throughputs).

Otherwise, that looks right. You'll probably end up with a different (and lower) answer when using 5-minute intervals than when using 10-second intervals, unless you have uncharacteristically smooth bandwidth usage, but both would be the 95th percentile for the interval in question.

-
It is a cisco snmp nagios script I grabbed from the exchange, and the data goes up down so it must be through interval. – Kyle Brandt Mar 16 '10 at 14:51
And my 5 minute average was lower as I expected. – Kyle Brandt Mar 16 '10 at 14:52
OK, you want to capture IfOutOctets and IfInOctets and then diff that against the previous entry captured. That way, you can (relatively easily) get measurements for any multiple of your polling interval by ignoring any values between the start and end of the period you want an average transfer rate over. – Vatine Mar 17 '10 at 16:02