How to use SNMP and MRTG to monitor the network traffic load on Red Hat Enterprise Linux
Environment
- Red Hat Enterprise Linux (3/4/5)
Issue
- How to use SNMP and MRTG to monitor the network traffic load on Red Hat Enterprise Linux
Resolution
Simple Network Management Protocol (SNMP) is a protocol used for network management. The NET-SNMP project includes various SNMP tools: an extensible agent, an SNMP library, tools for requesting or setting information from SNMP agents, tools for generating and handling SNMP traps, a version of the netstat
command which uses SNMP, and a Tk/Perl MIB browser. This package contains the snmpd
and snmptrapd
daemons, documentation, etc.
In addition to this, install the net-snmp-utils
package, which contains NET-SNMP utilities.
The Multi Router Traffic Grapher (MRTG) is a tool to monitor the traffic load on network-links. MRTG generates HTML pages containing PNG images which provide a live visual representation of this traffic.
Usually SNMP gets the network traffic from network devices. MRTG can get the traffic from SNMP then translate it to an image and output a HTML web page for users.
Below is the procedure to install and configure the snmp
and mrtg
. For this example, assume the IP address is 192.168.0.20
.
Be sure the packages listed below are installed. Use the rpm -qa packagename
command to check and up2date
to install any missing packages.
net-snmp-libs
net-snmp
net-snmp-devel
net-snmp-perl
net-snmp-utils
mrtg
Edit the /etc/snmpd/snmpd.conf
file (in the position near line 62 and line 89), changing this line:
access notConfigGroup "" any noauth exact systemview none none
to
access notConfigGroup "" any noauth exact mib2 none none
In the same file, uncomment this line by removing the pound sign (#
):
view mib2 included .iso.org.dod.internet.mgmt.mib-2 fc
Save the file and restart the snmpd
service:
service snmpd restart
chkconfig snmpd on
Now that snmp
is configured, the next step is to configure mrtg
software. The mrtg
package installs to the directory /var/www/mrtg
, so change to the directory and run the following command to generate the mrtg
configuration file:
# cd /var/www/mrtg
# cfgmaker --global "WorkDir: /var/www/html/mrtg" --global "Options[_]: growright,bits" --output=/var/www/mrtg/mrtg.cfg
public@192.168.0.20
Now in the /var/www/mrtg directory
, there is a file mrtg.cfg
generated which is the mrtg
configuration file.
After snmp
and mrtg
are configured, configure the Apache web server to serve out the mrtg
pages. Start by editing the /etc/httpd/conf/httpd.conf
file. Edit the section DocumentRoot
section as below:
DocumentRoot "/var/www/html/mrtg"
Now, create that directory:
# mkdir /var/www/html/mrtg/
Start the Apache service:
# service httpd start
# chkconfig httpd on
Next, generate the index of the web page as follows:
# indexmaker --output=/var/www/html/mrtg/index.html --Title=NetTraffic /var/www/mrtg/mrtg.cfg
Start the monitor program as follows:
# mrtg /var/www/mrtg/mrtg.cfg
If there is a warning message, run this command:
# env LANG=C /usr/bin/mrtg /var/www/mrtg/mrtg.cfg
To test the set up, go to the machine's address--for example http://192.168.0.20
. There will be a web page with network statistics.
Adding a cron job will run the commands to get the network status regularly. Here is an example:
* /5* * * * /usr/bin/mrtg /var/www/mrtg/mrtg.cfg
For more information about snmp
and mrtg
, see their man pages.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments