In “An introduction to SNMP” I have explained how SNMP protocol works and how use it; but what are the softwares that use SNMP to monitor network bandwith? HP Openview, Ciscoworks, MRTG are some examples.
In this article I will explain how monitor Cisco Switches/Routers bandwith under a Linux machine using a free open source tool: MRTG.
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.
MRTG consists of a Perl script which uses SNMP to read the traffic counters of your routers and a fast C program which logs the traffic data and creates beautiful graphs representing the traffic on the monitored network connection. These graphs are embedded into webpages which can be viewed from any modern Web-browser.
In addition to a detailed daily view, MRTG also creates visual representations of the traffic seen during the last seven days, the last five weeks and the last twelve months. This is possible because MRTG keeps a log of all the data it has pulled from the router. This log is automatically consolidated so that it does not grow over time, but still contains all the relevant data for all the traffic seen over the last two years. This is all performed in an efficient manner. Therefore you can monitor 200 or more network links from any halfway decent Linux/Windows/NetWare box.
MRTG is not limited to monitoring traffic, though. It is possible to monitor any SNMP variable you choose. You can even use an external program to gather the data which should be monitored via MRTG. People are using MRTG, to monitor things such as System Load, Login Sessions, Modem availability and more. MRTG even allows you to accumulate two or more data sources into a single graph.
- You need to install MRTG package; for instance, if you use Fedora distribution use “yum install mrtg” command or, on Mandriva distribution, use “urpmi mrtg” command.
- You need to activate snmp service on router/switch; type “snmp-server community ciscozine_32public RO” command on global configuration to activate the snmp server in read-only mode with the key (it’s like a password) ciscozine_32public.
Login on the Linux machine and go to the www_root folder (it’s something like “/var/www/html/”), then make a new folder and go inside:
[root@linux-ciscozine ~]# [root@linux-ciscozine ~]# cd /var/www/html/ [root@linux-ciscozine html]# mkdir Cisco-MRTG [root@linux-ciscozine html]# cd Cisco-MRTG/
Create the MRTG configuration files based on information pulled from the Cisco element, using the “cfgmaker” command (192.168.1.20 is the Cisco IP address):
cfgmaker --global 'WorkDir: /var/www/html/Cisco-MRTG' \ email@example.com > Cisco-MRTG.cfg
Create the web page which display the status of an array of mrtg interface status pages, using the “indexmaker” command:
indexmaker Cisco-MRTG.cfg > index.html
Once you have created a configuration file, try the following:
env LANG=C /usr/bin/mrtg /var/www/html/Cisco-MRTG/Cisco-MRTG.cfg
This will query your router and also create your first mrtg trafic graphs and webpages. When you run mrtg for the first time there will be a lot of complaints about missing log files. Don’t worry, this is normal for the first 2 times you start mrtg. If it keeps complaining after this time you might want to look into the problem.
Starting mrtg by hand is not ideal in the long run. So when you are satisfied with the results you can automate the process of running mrtg in regular intervals (this means every 5 minutes by default). To define it type “crontab -e” command and paste this setting:
*/5 * * * * env LANG=C /usr/bin/mrtg /var/www/html/Cisco-MRTG/Cisco-MRTG.cfg
Now, if you have an http server on your Linux machine, you can access to the bandwith statistics via web browser.
Remember: Each 5 minutes the images showed in the web pages will be refreshed.