Monday, September 29, 2008

Monitoring Bandwidth usage with SNMP and RRDtool for Linux

Before monitor any server you need to install SNMP and RRDTool packages on monitor server and net-snmp package on server which you want to monitor.

lets assume server which has SNMP and RRDTool means monitor server has ip address
and server which you want to monitor has IP address

SNMP Installation
SNMP packages require for querring .

- type command at the prompt
#yum search snmp
It will show you different snmp packages.
You neet to install 2 packages
type command
#yum install net-snmp
#yum install net-snmp-devel

RRDTool Installation

RRD store and display time-series data (i.e. network bandwidth, server load average). It stores the data in a very compact way that will not expand over time, and it presents useful graphs by processing the data to enforce a certain data density.

RRDTool 1.2.x has dependancies ,hence you need to install following packages.

* libart_lgpl-2.3.11-2.i386.rpm
* libart_lgpl-devel-2.3.11-2.i386.rpm
* freetype-2.1.3-6.i386.rpm
* freetype-devel-2.1.3-6.i386.rpm
* zlib-1.1.4-8.i386.rpm
* zlib-devel-1.1.4-8.i386.rpm
* libpng-1.2.2-16.i386.rpm
* libpng-devel-1.2.2-16.i386.rpm

Download RRDTool from

lets assume you have rrdtool-1.2.12.tar.gz

To extract RRDTool run this command:

#tar -xzvf rrdtool-1.2.12.tar.gz

then change directory:
#cd rrdtool-1.2.12

to compile ans install RRDTool type:
#./configure –disable-tcl
#make install

Apply following step on server which you want to monitor means
Install net-snmp
Type following commands
#yum search snmp
#yum install net-snmp

then edit snmpd.conf file and create readonly community
#vi /etc/snmp/snmpd.conf

add following line in snmpd.conf file
rocommunity community_name ip_address_of_monitor_server

start snmpd service
/etc/init.d/snmpd start

Apply following step on monitor server means
To monitor bandwidth you need to create RRD file,which will store bandwidth data.

step 1
Create RRD file.
rrdtool create bandwidth.rrd -s 60 \
DS:in:COUNTER:300:U:U \
DS:out:COUNTER:300:U:U \

step 2
Update RRD file.

/usr/bin/rrdupdate bandwidth.rrd \
N:`/usr/bin/snmpget -v 1 -c community_name -Oqv IF-MIB::ifInOctets.2`: \
`/usr/bin/snmpget -v 1 -c community_name -Oqv IF-MIB::ifOutOctets.2`

Above command should be run with 1 or 5 minute interval as per your need,hence add above command in cronjob.

step 3
Generate graph from bandwidth.rrd file

rrdtool graph bandwidth.png \
–end now –start end-30h –width 400 \
–x-grid HOUR:1:HOUR:6:HOUR:2:0:%H \
–imgformat=PNG \
–title=”your title” \
–rigid \
–base=1000 \
–height=120 \
–width=500 \
–alt-autoscale-max \
–lower-limit=0 \
–vertical-label=”bits per second” \
DEF:a=bandwidth.rrd:in:AVERAGE \
DEF:b=bandwidth.rrd:out:AVERAGE \
VDEF:totin=a,TOTAL \
VDEF:totout=b,TOTAL \
CDEF:cdefa=a,8,* \
CDEF:cdeff=b,8,* \
AREA:cdefa#00CF00:”Incoming” \
GPRINT:cdefa:LAST:”Cur\:%6.2lf %sb/s” \
GPRINT:cdefa:AVERAGE:”Avg\:%6.2lf %sb/s” \
GPRINT:cdefa:MAX:”Max\:%6.2lf %sb/s” \
GPRINT:cdefa:MIN:”MIN\:%6.2lf %sb/s\l” \
LINE1.3:cdeff#0000FF:”Outgoing” \
GPRINT:cdeff:LAST:”Cur\:%6.2lf %sb/s” \
GPRINT:cdeff:AVERAGE:”Avg\:%6.2lf %sb/s” \
GPRINT:cdeff:MAX:”Max\:%6.2lf %sb/s” \
GPRINT:cdeff:MIN:”MIN\:%6.2lf %sb/s\l” \
GPRINT:totin:”Total IN\:%6.2lf %sb/s” \
GPRINT:totout:”Total OUT\:%6.2lf %sb/s” \

After firing above command, a file bandwidth.png will be in current direcoty which is bandwidth graph for server

No comments: