MRTG is one of those tools a Network Engineer has on his/her toolbelt. MRTG allows the graphing of trending network activity for a wide range of devices. It uses SNMP to query a host and poll it’s network information and statistics. It can be used with Routers, Switches, Linux Hosts, etc.
I’m going to run MRTG against a Linux Router(running IPtables), a HP PowerConnect Switch, a Cisco Router, and an ESXi host. Anyway….Let’s get started.
Prepare SNMP Devices
-
Linux Router –Install SNMPd on the Linux Host being used as a router.
apt-get install snmpd
vi /etc/snmp/snmpd.conf #Paste in the follow: com2sec local localhost public com2sec mynetwork 10.0.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 Linux (RH3_UP2), Home Linux Router. syscontact Jim <jim@techjockey.net>
What we are doing here is setting up the default settings for SNMPd. local is the Read/Write group profile, which will only be localhost. mynetwork is the Read Only group profile, which will be accessable by any host address on the 10.0.0.0/24.
service snmpd restart
-
PowerConnect Switch
SW1# conf t SW1(conf)# snmp-server 10.0.0.9 SW1(conf)# snmp-server community public ro view Default SW1(conf)# exit SW1# copy running-config startup-config
Note:We are setting the snmp server IP and the community string of public to Read Only.This way when MRTG trys to query SNMP statistics it will have permissions to read the Switch’s metrics.
-
Cisco Switch/Router
Router# conf t Router(config)# snmp-server community public RO Router(config)# snmp-server host 10.0.0.9 Router(config)# end Router# wr me
Very similar to PowerConnect Switch
-
ESXi 5.1 Host
- Get the current Community
esxcli system snmp get Authentication: Communities: public Enable: false Engineid: 00000063000000a1c0a8000a Hwsrc: indications Loglevel: info Notraps: Port: 161 Privacy: Remoteusers: Syscontact: Syslocation: Targets: Users: V3targets:
Notice, SNMP is currently not enabled. So we need to enable it :-p
- Enable SNMP
esxcli system snmp set --enable 1 esxcli system snmp set --communities public --targets 10.0.0.9 esxcli system snmp test
This will configure the ESXi host to use community public and trust 10.0.0.9
- Get the current Community
Setting up the MRTG Collector
-
-
First off, install MRTG:
apt-get install mrtg apache2
-
Create a MRTG config for each Device
Run the cfgmaker command to auto populate the cfg for this type of host. This will create a config file for this device type….
cfgmaker --global "WorkDir: /var/www/mrtg/router" --output /etc/mrtg.d/router.cfg --ifref=name public@10.0.0.1
We assume 10.0.0.1 is our Router
-
Create an Index.html page for each Device
indexmaker --output /var/www/mrtg/router/index.html /etc/mrtg.d/router.cfg env LANG=C mrtg /etc/mrtg.d/router.cfg
Notice, The indexmaker reads the MRTG config file that you made above and creates HTML to present the graphs for each interface.
-
Configure CRON job to periodically poll each Device
-
vi /etc/cron.d/mrtg #Paste the following for each device: /5 * * * * root env LANG=C mrtg /etc/mrtg.d/router.cfg
Notice, the above line sets a cron job to run every 5 minutes and run MRTG using configuration file router.cfg. So if you have multiple devices, just add a new line for each one.
Sources:
- http://oss.oetiker.ch/mrtg/doc/cfgmaker.en.html
- http://www.my-guides.net/en/guides/linux/how-to-install-mrtg-under-linux
- http://write.keinism.com/2008/02/29/create-new-mrtg-graph-8-steps/
- http://www.cyberciti.biz/nixcraft/linux/docs/uniqlinuxfeatures/mrtg/mrtg_config_step_7.php
- http://www.debianadmin.com/mrtg-installation-and-configuration-in-debian-based-distributions-2.html
- http://www.debianhelp.co.uk/mrtg.htm
I have been looking for a simple way to do this for, well, I am embarrassed to say for how long. It never occurred to me to do multiple configs this way. Thanks much!