Skip to content


How to install MRTG (Multi Router Traffic Grapher).

Most of the times people probably wonder how much traffic is flowing through servers. At this point, you probably want to monitor how much bandwidth you are using. One of the best tools you can use is MRTG (Multi Router Traffic Grapher). It is not very hard to setup MRTG and requires only few packages to be installed.

First of all we have to install SNMP service.

[root@p-root /opt]# rpm -qa | grep snmp

[root@p-root /opt]# yum install net-snmp net-snmp-utils

[root@p-root /opt]# service snmpd start

[root@p-root /opt]# chkconfig –add snmpd

[root@p-root /opt]# chkconfig –levels 2345 snmpd on

Run this command,whether is’t working or not,if you get the below output means it’s working:

[root@p-root /opt]# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1

IP-MIB::ipAdEntIfIndex.192.168.0.128 = INTEGER: 2

Now configure snmpd.conf file. Please take backup of default snmpd.conf file and create new one.

[root@p-root /opt]# mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak


[root@p-root /opt]# vi /etc/snmp/snmpd.conf

Replace the content in there with following:-

com2sec local localhost public
com2sec mynetwork 192.168.0.0/24 public
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 mynetwork
group MyROGroup v2c mynetwork
group MyROGroup usm mynetwork
view all included .1 80
access MyROGroup “” any noauth exact all none none
access MyRWGroup “” any noauth exact all all none
syslocation “Some place out there”
syscontact Admin <admin@unixsurgeon.com>

Here i am sharing my configuration file  :-

##########################################################

#

# snmpd.conf

#

# – created by the snmpconf configuration program

#

##########################################################

# SECTION: Access Control Setup

#

# This section defines who is allowed to talk to your running

# snmp agent.

# rocommunity: a SNMPv1/SNMPv2c read-only access community name

# arguments: community [default|hostname|network/bits] [oid]

com2sec local localhost private

com2sec mynetwork 192.168.0.0/24 public

com2sec mynetwork 115.110.x.x/32 public

group MyRWGroup v1 local

group MyRWGroup v2c local

group MyRWGroup usm local

group MyROGroup v1 mynetwork

group MyROGroup v2c mynetwork

group MyROGroup usm mynetwork

view     all        included         .1         80

access MyROGroup  ” “  any noauth exact all none none

access MyRWGroup  ” “  any noauth exact all all none

syslocation Linux (RH3_UP2), Linux Router.

[root@p-root /opt]# service snmpd restart

Now test your SNMP server.

[root@p-root /opt]# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex

IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1

IP-MIB::ipAdEntIfIndex.192.168.0.128 = INTEGER: 2

Ok. That is all we will do with SNMP. Let us continue MRTG installation.

[root@p-root /opt]# rpm -qa | grep mrtg

[root@p-root /opt]# yum install mrtg

Let us set up data directory to store html files:

[root@p-root /opt]# mkdir /var/www/html/mrtg

Now let us set up mrtg.conf to use for monitoring bandwidth usage:

[root@p-root /opt]# cfgmaker public@192.168.0.128 –global “WorkDir: /var/www/html/mrtg” –output=/etc/mrtg/mrtg.cfg

Let us create index file for MRTG page:

[root@p-root /opt]# indexmaker –output=/var/www/html/mrtg/index.html /etc/mrtg/mrtg.cfg

It is time for us to tell Apache to serve these pages

[root@p-root /opt]# vi /usr/local/apache2/conf/httpd.conf

Alias /mrtg /var/www/html/mrtg
<location /mrtg>
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.0.0/24
</location>

[root@p-root /opt]# snmpwalk -v 1 -c public 192.168.0.128 interface

[root@p-root /opt]# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg

[root@p-root /opt]# crontab -e

*/5 * * * * /usr/bin/mrtg /etc/mrtg/mrtg.cfg –logging /var/log/mrtg.log

Open this link in your browser and it will show like this.

http://192.168.0.128/mrtg

mrtg
Protect your MRTG graphs with password protected directory :-

To restrict access to your MRTG reports. This can easily accomplished with Apache webserver’s .htaccess file.

Below is process to protect graphs using apache’s .htaccess file and htpasswd command:

Step # 1: Create .htaccess file in /var/www/html/mymrtg/ directory (add text as follows):

[root@p-root /]# vi /var/www/html/mymrtg/.htaccess

Then Add following text to file:-

AuthName “MRTG Graphs Restricted Access”
AuthType Basic
AuthUserFile /var/members/.htpasswd
require user unixsurgeon

Step # 2: Create a user and password name (-c assumes first time you are using .htpasswd file):-

[root@p-root /]# htpasswd -c /var/members/.htpasswd unixsurgeon

=============================================================================================

Enjoy Linux !!!

Posted in Linux tutorials, Monitoring Tool, Open Source Applications.

Tagged with .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

You must be logged in to post a comment.