Date created: Sunday, January 20, 2013 3:47:46 PM. Last modified: Tuesday, September 19, 2017 12:03:12 PM

RRDTool Total Bandwidth In & Out

See Also:
An explenation of 95th percentile, mean, media and mode: /index.php?page=95th-percentile-and-mean-median-mode
Notes on 95th percentile accuracy with rrdtools: /index.php?page=95th-percentile-accuracy-with-rrdtools

Calculate the total amount of bandwidth transferred in an rra file. Separate in and out amounts can be generated from the two data streams, in this example 'traffic_in' and 'traffic out'. RRDTool will generate the amount using the TOTAL function (as of rrdtool v1.2 and newer), by taking the average transfer rate across a time period and performing a "speed over time" calculation.

This is flawed if there are any missing samples or unknown values. These can either be replaces with a 0, which lowers the average, or we can calculate an average throughput for the month, then use that for any missing values;

#!/bin/bash

#datestart=`date -d "-1 month -$(($(date +%d)-1)) days 00:00" "+%s"`
#dateend=`date -d "-$(date +%d) days 23:59:59" "+%s"`

echo -n "Average, with unknowns set to average value:"

rrdtool graph -f '' -s $1 -e $2 /dev/null \
DEF:in="$3":traffic_in:AVERAGE \
DEF:out="$3":traffic_out:AVERAGE \
VDEF:inbytesavg=in,AVERAGE \
VDEF:outbytesavg=out,AVERAGE \
CDEF:inbytesmod=in,UN,inbytesavg,in,IF \
CDEF:outbytesmod=out,UN,outbytesavg,out,IF \
VDEF:intotal=inbytesmod,TOTAL \
VDEF:outtotal=outbytesmod,TOTAL \
PRINT:intotal:"Total In\:%.2lf %SB" \
PRINT:outtotal:"Total Out\:%.2lf %SB"


echo -e -n "\nAverage, with unknowns set to zero:"

rrdtool graph -f '' -s $1 -e $2 /dev/null \
DEF:in="$3":traffic_in:AVERAGE \
DEF:out="$3":traffic_out:AVERAGE \
CDEF:inbytesmod=in,UN,0,in,IF \
CDEF:outbytesmod=out,UN,0,out,IF \
VDEF:intotal=inbytesmod,TOTAL \
VDEF:outtotal=outbytesmod,TOTAL \
PRINT:intotal:"Total In\:%.2lf %SB" \
PRINT:outtotal:"Total Out\:%.2lf %SB"


echo -e -n "\nMax, with unknowns set to average value:"

rrdtool graph -f '' -s $1 -e $2 /dev/null \
DEF:in="$3":traffic_in:MAX \
DEF:out="$3":traffic_out:MAX \
VDEF:inbytesavg=in,AVERAGE \
VDEF:outbytesavg=out,AVERAGE \
CDEF:inbytesmod=in,UN,inbytesavg,in,IF \
CDEF:outbytesmod=out,UN,outbytesavg,out,IF \
VDEF:intotal=inbytesmod,TOTAL \
VDEF:outtotal=outbytesmod,TOTAL \
PRINT:intotal:"Total In\:%.2lf %SB" \
PRINT:outtotal:"Total Out\:%.2lf %SB"


echo -e -n "\nMax, with unknowns set to zero:"

rrdtool graph -f '' -s $1 -e $2 /dev/null \
DEF:in="$3":traffic_in:MAX \
DEF:out="$3":traffic_out:MAX \
CDEF:inbytesmod=in,UN,0,in,IF \
CDEF:outbytesmod=out,UN,0,out,IF \
VDEF:intotal=inbytesmod,TOTAL \
VDEF:outtotal=outbytesmod,TOTAL \
PRINT:intotal:"Total In\:%.2lf %SB" \
PRINT:outtotal:"Total Out\:%.2lf %SB"

#Example output:
#Total In:23.88 GB
#Total Out:15.02 GB 
james.bensley@s1:~$ ./rrdtotal 1358501007 1358508207 ar01_traffic_in_5547.rrd
Average, with unknowns set to average value:
Total In:68.49 GB
Total Out:8.33 GB

Average, with unknowns set to zero:
Total In:65.75 GB
Total Out:8.00 GB

Max, with unknowns set to average value:
Total In:68.49 GB
Total Out:8.33 GB

Max, with unknowns set to zero:
Total In:65.75 GB
Total Out:8.00 GB