There are several ways to monitor your system health and network status, each with its own advantages and disadvantages. And I would like to share with you with here a simple way by using snmp and mrtg to monitor your network traffic.
Let’s go straight to the practical part, and if you want to know more about snmp and mrtg please navigate to the following websites:
http://www.net-snmp.org/
http://oss.oetiker.ch/mrtg/
First you need to have following packages installed -
- lm_sensors
- net-snmp
- net-snmp-utils
- mrtg
If you are running on a Fedora, then ‘yum install <package-name>‘ will do, else you need to consult your Linux distribution’s manual for how to install those packages.
Now, let’s create a simple /etc/snmp/snmpd.conf. Below is a simple one -
com2sec localnet localhost public
com2sec officenet 192.168.1.0/24 public
group localgroup any localnet
group officegroup any officenet
view all included .1 80
access localgroup “” any noauth exact all all all
access officegroup “” any noauth exact all all all
syslocation Office
syscontact SystemAdmin
Then start the snmpd service and turn it on during boot time -
# service snmpd start
# chkconfig snmpd on
Now let’s configure mrtg -
# cfgmaker –gloabal “WorkDir: /var/www/html/mrtg” \
–global “Options[_]: growright,bits” \
–ifref=ip \
–output /etc/mrtg/local.cfg public@localhost
# cfgmaker –gloabal “WorkDir: /var/www/html/mrtg” \
–global “Options[_]: growright,bits” \
–ifref=ip \
–output /etc/mrtg/office.cfg public@192.168.1.0
# cd /etc/mrtg
# cat local.cfg >> mrtg.cfg
# cat office.cfg >> mrtg.cfg
# mkdir /var/www/html/mrtg
# env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg (run this line 3 times)
# indexmaker –output /var/www/html/mrtg/index.html \
–title=MRTG /etc/mrtg/mrtg.cfg
If you web server is not yet started, then start it now -
# service httpd start
# chkconfig httpd on
Now let’s add it to cron -
# crontab -e
*/5 * * * * /usr/bin/env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg /dev/null 2>&1
An example graph by snmp & mrtg -
