Aug 15, 2012

Install MRTG and SNMP

The Multi Router Traffic Grapher (MRTG) is a tool to monitor the network traffic load. With this tool you can even monitor router traffic. Before we configure MRTG, we need a working Simple Network Management Protocol (SNMP) server.

1. Install snmp packages

yum install snmp net-snmp net-snmp-utils -y

2. Configure SNMP

vi /etc/snmp/snmpd.conf

Locate line that contains:
com2sec notConfigUser default public

Add or change to as follows, in case of 192.168.0.0/24, enter your own internal network range:

com2sec local localhost public
com2sec mynetwork 192.168.0.0/24 public

Locate line that contains:

group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser


Add or change to as follows:
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork

Locate line that contains:
view systemview included system

Add or change to:
view all included .1 80

Locate a line that contains:
access notConfigGroup "" any noauth exact systemview none none

Add or change to:
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all none

Thats it, now start the service,
service snmpd start
and make the service to start when ever the server boots
chkconfig snmpd on

Test id SNMP is working properly:
snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

3. Install MRTG and apache web server
yum install mrtg httpd -y

4. Run cfgmake to create a mrtg configuration file. We want to monitor traffic for the server with IP 192.168.0.1. You can create as many configuration as possible based on ip.

cfgmaker --global 'WorkDir: /var/www/mrtg' --output /etc/mrtg/192.168.0.1.cfg public@192.168.0.1

You can even merge multiple configuration file to on configuration file so that you can make a index page from it, which would contain traffic graph from multiple ip's on a single index page.

cat /etc/mrtg/*.cfg >> /etc/mrtg/mrtg.cfg


5. Now create a index page from mrtg configuration file that we just create above i.e. 192.168.0.1.cfg
indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/192.168.0.1.cfg
In the section no. 4 we had also merged multiple cfg file to one mrtg.cfg file. So if you want to create a index file for multiple interface to one then run
indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg


6. Small change in apache server confguration, so that local network range can view the mrtg page.

vi /etc/httpd/conf.d/mrtg.conf

locate the below line and modify as follows
Allow from 127.0.0.1 192.168.0.0/24

Restart the web service
service httpd restart

No comments:

Post a Comment