Tuesday 11 June 2013

Bandwidth monitoring using Multi Router Traffic Grapher ( MRTG )

MRTG monitor SNMP network devices and draw pretty pictures showing how much traffic has passed through each interface. Initial days MRTG is being used to graph only network devices but now it can monitor everything from weather data to vending machines. MRTG generates HTML pages with images of PNG, which show the amount of traffic passing through the interface. If you want MRTG on your system, you need to have SNMP configured and running. But you don't need to configure SNMP for router, as most router and switches comes with pre-configured SNMP.

INSTALLATION
You can install using yum, if you want the latest version running on system you need to install manually from here.

# yum install mrtg

CONFIGURATION
You need to create the folder in which your graphs and html pages has to be stored.

# mkdir /var/www/html/mrtg/

Run the cfgmaker to create the mrtg configuration file /etc/mrtg/mrtg.cfg

# cfgmaker --global "workdir: /var/www/html/mrtg" -ifref=ip --output /etc/mrtg/mrtg.cfg --global 'options[_]: growright,bits' public@<router-ip-address>

Here you can see that --output /etc/mrtg/mrtg.cfg as long as to public@<router-ip-address>. This command tells the MRTG to create a configuration file with the name ‘mrtg.cfg’ for the traffic of your router.

Next we use indexmaker to creates index files for mrtg web sites

# indexmaker --output=/var/www/html/mrtg/index.html /etc/mrtg/mrtg.cfg

CRON JOB
/etc/cron.d/mrtg executes mrtg command in every 5 minutes to graph the traffic load on network links. If you run

# cat /etc/cron.d/mrtg

You should see something like

*/5 * * * * root LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok

You need to make sure crond is running on run level 3 and 5, # chkconfig --level 35 crond on

VERIFY
When you run the command # mrtg /etc/mrtg/mrtg.cfg, if you see something like
 -----------------------------------------------------------------------
ERROR: Mrtg will most likely not work properly when the environment
       variable LANG is set to UTF-8. Please run mrtg in an environment
       where this is not the case. Try the following command to start:

       env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg
-----------------------------------------------------------------------
then, you need to run the above command few more times till it runs without any error, this is quite normal.

MRTG GRAPHS
You need to have Apache web server to view graphs, simply type the following to install httpd:
# yum install httpd (Obviously you need to configure the apache).
# chkconfig --level 3 httpd on
# service httpd on

Fire your favorite web browser and type http://your-router-ip/mrtg. Now your graph will be something like


No comments:

Post a Comment