Please note: This project is no longer active. The website is kept online for historic purposes only.
If you´re looking for a Linux driver for your Atheros WLAN device, you should continue here .

Graphing Bandwidth with snmpget and rrdtool

Using the snmpget and rrdtool to log the input and output data throughput. Then view the captured data.

Output

The graph from the day-net-ath0.png will look similar to this:

Bandwidth Data throughtput

Create

First create a rrdtool database using:

#! /bin/bash
# create-throughput.sh

# check every 5 minutes for 7 days
rrdtool create /var/lib/sensord/throughput.rrd --start N \
  DS:in:COUNTER:600:U:U \
  DS:out:COUNTER:600:U:U \
  RRA:AVERAGE:0.5:1:2016

If you wish to graph the data more or less frequently then change 2016 and 600. 2016 is calculated by 7 days * 24 hours * 60 minutes / 5 minutes per update. 600 is 10 minutes * 60 seconds and represents that when no data is added in 600 seconds then there is a break in the output.

Update

Add a script to update the rrdtool database

#! /bin/bash
# update-throughput.sh

# check every 5 minute for 7 days
/usr/bin/rrdupdate /var/lib/sensord/throughput.rrd \
  N:\
  $(/usr/bin/snmpget -v 1 -c public -Oqv localhost IF-MIB::ifInOctets.4):\
  $(/usr/bin/snmpget -v 1 -c public -Oqv localhost IF-MIB::ifOutOctets.4)

Then capture that data every minute with a cron job

*/5 * * * * update-throughput.sh

Generate Graph

Graphing with python and the rrdtool module

#! /usr/bin/python
# graph-throughput.py

import rrdtool

# Generate a graph of the last 24 hours of the data throughput
rrdtool.graph('day-net-ath0.png',
    '--imgformat', 'PNG',
    '--height', '200', '--width', '800',
    '--lazy',
    '--title', 'Day Network Load (ath0)',
    '--vertical-label', 'Data Throughput',
    '--start', '-1days',
    '--x-grid', 'HOUR:1:HOUR:3:HOUR:3:0:%b %d %H:00',
    'DEF:in=/var/lib/sensord/throughput.rrd:in:AVERAGE',
    'DEF:out=/var/lib/sensord/throughput.rrd:out:AVERAGE',
    'CDEF:kbin=in,1024,/',
    'CDEF:kbout=out,1024,/',
    'AREA:in#00FF00:Bandwidth In',
    'LINE1:out#0000FF:Bandwidth Out\j',
    'GPRINT:kbin:LAST:Last Bandwidth In\:     %5.2lf Kbps',
    'GPRINT:kbout:LAST:Last Bandwidth Out\:    %5.2lf Kbps\j',
    'GPRINT:kbin:AVERAGE:Average Bandwidth In\:  %5.2lf Kbps',
    'GPRINT:kbout:AVERAGE:Average Bandwidth Out\: %5.2lf Kbps\j')

# Generate a graph of the last 7 days of the data throughput
rrdtool.graph('week-net-ath0.png',
    '--imgformat', 'PNG',
    '--height', '200', '--width', '800',
    '--lazy',
    '--title', 'Week Network Load (ath0)',
    '--vertical-label', 'Data Throughput',
    '--start', '-1week',
    '--x-grid', 'HOUR:6:DAY:1:DAY:1:86400:%a %b %d',
    'DEF:in=/var/lib/sensord/throughput.rrd:in:AVERAGE',
    'DEF:out=/var/lib/sensord/throughput.rrd:out:AVERAGE',
    'CDEF:kbin=in,1024,/',
    'CDEF:kbout=out,1024,/',
    'AREA:in#00FF00:Bandwidth In',
    'LINE1:out#0000FF:Bandwidth Out\j',
    'GPRINT:kbin:LAST:Last Bandwidth In\:     %5.2lf Kbps',
    'GPRINT:kbout:LAST:Last Bandwidth Out\:    %5.2lf Kbps\j',
    'GPRINT:kbin:AVERAGE:Average Bandwidth In\:  %5.2lf Kbps',
    'GPRINT:kbout:AVERAGE:Average Bandwidth Out\: %5.2lf Kbps\j')

The command line version of graph is similar to above.

Attachments