Monitoring bandwidth with RRDtool and SNMP
Monitoring is an important component of providing a reliable and professional service. One primary and common type of monitoring is historic monitoring. It is used for recording long-term uptime, usage and performance statistics.
This example will use RRDtool and Simple Network Management Protocol (SNMP) on a FreeBSD operating system to monitor the network traffic on a network interface. RRDtool is an open source industry monitoring standard, that can be used to log and graph data series over time.
Log in as root and install RRDtool and SNMP.
cd /usr/ports/databases/rrdtool && make install
cd /usr/ports/net-mgmt/net-snmp && make install
Configure the SNMP daemon.
snmpconf -i
cp /usr/local/share/snmp/snmpd.conf /usr/local/etc/
Choose snmpd.conf. Choose “System Information Setup”. Go through all settings. Choose “a SNMPv1/SNMPv2c read-only access community name”. Choose “The IP address and port number that the agent will listen on”. 127.0.0.1.
nano -w /etc/rc.conf
snmpd_enable="YES"
Start the SNMP daemon.
/usr/local/etc/rc.d/snmpd start
The SNMP daemon is now ready to return values for monitoring. In order to get values from a specific sensor (object), such as an interface, you need to find the specific object identifier (OID) from the Management Information Base (MIB). Every OID is structured in a tree of numbers (nodes), that is separated by dots. Network interfaces are found under 1.3.6.1.2.1.
Find the specific OID for the network interface by taking a walk in the MIB and looking for the name of the interface.
snmpwalk -v 1 -c community host | grep ifDescr
Test a read of the counter for inbound traffic and a read of the counter for outbound traffic.
snmpget -v 1 -c community -Oqv host IF-MIB::ifInOctets.interface IF-MIB::ifOutOctets.interface
The following commands will create a database, that will expect samples and archive samples.
In this example, the database will start now, expect 1 sample every 5 min (300 s) from the in counter, expect 1 sample every 5 min (300 s) from the out counter, archive 576 samples (2 days) of data, archive 672 samples as an average of every 6 samples (2 weeks of 30 min averages), archive 732 samples as an average of every 24 samples (12 weeks of 2 hour averages) and archive 1.460 samples as an average of every 144 samples (2 years of 12 hour averages). In order to have a fine graph, you need to have at least the number of samples, that equals the number of pixels, within the time frame, that you want to show. You can ensure, that you are using correct settings, using the following mathematical relations.
RRA:AVERAGE:0.5:a:n
t = ran [min] = rn/60 [hours] = ran/1440 [days] = ran/10080 [weeks]
t: Length of archive in time. r: Rate of samples per min. a: Number of samples used for an average. n: Length of archive in number of samples.
mkdir -p /var/db/rrd
rrdtool create /var/db/rrd/bandwidth.rrd --start N --step 300 DS:in:COUNTER:600:U:U DS:out:COUNTER:600:U:U RRA:AVERAGE:0.5:1:576 RRA:AVERAGE:0.5:6:672 RRA:AVERAGE:0.5:24:732 RRA:AVERAGE:0.5:144:1460
The following commands and configuration will ensure, that samples are taken every 5th minute at the correct time, and, that the graphs is drawn.
nano -w /etc/crontab
0-55/5 * * * * root /usr/local/bin/rrdupdate /var/db/rrd/bandwidth.rrd N:`/usr/local/bin/snmpget -v 1 -c community -Oqv host IF-MIB::ifInOctets.interface`:`/usr/local/bin/snmpget -v 1 -c community -Oqv host IF-MIB::ifOutOctets.interface`
0-45/15 * * * * root /usr/local/bin/rrdtool graph 'graph' --start '-2days' --width '485' --title 'title' -v 'kb/s' 'DEF:in=/var/db/rrd/bandwidth.rrd:in:AVERAGE' 'DEF:out=/var/db/rrd/bandwidth.rrd:out:AVERAGE' 'CDEF:kbin=in,1000,/' 'CDEF:outi=0,out,-' 'CDEF:kbout=outi,1000,/' 'AREA:kbin#66FF66:In' 'AREA:kbout#6666FF:Out' >> /dev/null
killall -HUP cron
The graphs can be exported to a central host via local network or via internet in a secure form using trusted (passwordless) secure copy (scp).
0-45/15 * * * * root /usr/local/bin/rrdtool graph 'graph' --start '-2days' --width '485' --title 'title' -v 'kb/s' 'DEF:in=/var/db/rrd/bandwidth.rrd:in:AVERAGE' 'DEF:out=/var/db/rrd/bandwidth.rrd:out:AVERAGE' 'CDEF:kbin=in,1000,/' 'CDEF:outi=0,out,-' 'CDEF:kbout=outi,1000,/' 'AREA:kbin#66FF66:In' 'AREA:kbout#6666FF:Out' >> /dev/null && scp user@host:path
You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.