How to setup MRTG on Centos (RHEL) 4.x and 5.x? Rumi, February 9, 2010July 30, 2011 MRTG stands for "Multi Router Traffic Grapher", and it is a tool to monitor the traffic load on the network interfaces. It generates HTML pages containing PNG images which depicts visual representation of inbound and outbound traffic. MRTG is free software designed by Tobi Oetiker and is licensed under the Gnu GPL. Most Linux distributions include MRTG as an RPM package, which you can install; or download the latest copy from the official MRTG website. You may also install MRTG on Windows platform. MRTG uses a highly portable SNMP implementation written in Perl programming language, which interacts with SNMP agent to receive traffic characteristics. To use MRTG to draw pretty traffic graphs, the server running MRTG must communicate with SNMP agent. Most routers these days support SNMP agent functionality. If you do not have control over a router, you may install and run any snmp agent (i.e. net-snmp on linux distributions) on the server where you want to monitor traffic. To learn more about snmp, please consult MRTG and SNMP Overview. 1. Setup SNMP Agent In order for SNMP Manager such as the MRTG to poll information from a Router (or a server), we need to setup SNMP community on the SNMP agent. If you have the control over a router, you may simply setup a read-only (public) community on the router. Most routers today support SNMP agent functionality. You may have to follow your SNMP agent documentation to configure the public community that will allow MRTG to poll information from it. On a Cisco router, you may use the following command to configure public community: cisco# snmp-server community public RO If you have other brand of router, check with manufacturer's manual to determine how to configure SNMP community that will allow SNMP managers to query information from a MIB. If you do not have an access to a router or prefer installing SNMP agent on your server, you may install SNMP agent on the server. There are a couple of SNMP packages that are available on Linux platform: cmu-snmp and net-snmp. You may install any SNMP packages (available as a RPM or tarball), and they will work virtually the same. bash# yum install net-snmp On Debian/Ubuntu Distribution use- bash# apt-get install snmpd If you have installed net-snmp package, you may configure read-only community by replacing snmp configuration file, /etc/snmp/snmpd.conf, with the following: # Content of /etc/snmp/snmpd.conf rocommunity public # Start the snmpd daemon on Linux command-line. bash# service snmpd start # Allow snmpd damon to restart on reboot bash# chkconfig snmpd on 2. Install and configure MRTG Most Linux distributions include MRTG as an RPM package. You may install MRTG with 'yum' command. You may also use cfgmaker script to build configuration file for MRTG. bash# yum install mrtg bash# cfgmaker {community}@{SNMP agent host IP} > /etc/mrtg/mrtg.cfg #OR, for an example: bash# cfgmaker public@localhost > /etc/mrtg/mrtg.cfg For Debian/Ubuntu- bash# apt-get install mrtg bash# cfgmaker {community}@{SNMP agent host IP} > /etc/mrtg/mrtg.cfg #OR, for an example: bash# cfgmaker public@localhost > /etc/mrtg.cfg The cfgmaker script will discover every interface in your router and write a section in the configuration file with its interface number, speed and description. You may edit mrtg.cfg file manually to further customize the configuration for your environment. 3. Run MRTG Running mrtg is very straight-forward. Simply run mrtg with the configuration file built in the previous step. bash# mrtg /etc/mrtg/mrtg.conf ### ### You may see following error messages when you run 'mrtg' for the first time. ### You may ignore them, as necessary files will created (and removed) as you run ### 'mrtg' multiple times to monitor network traffic on a regular basis. ### bash# mrtg ———————————————————————– ERROR: Mrtg will most likely not work properly when the environment variable LANG is set to UTF-8. Please run mrtg in an environment where this is not the case. Try the following command to start: env LANG=C /usr/bin/mrtg ———————————————————————– bash# LANG=C bash# mrtg mrtg.cfg 21-08-2007 01:08:55, Rateup WARNING: /usr/bin/rateup could not read the primary log file for localhost_2 21-08-2007 01:08:55, Rateup WARNING: /usr/bin/rateup The backup log file for localhost_2 was invalid as well 21-08-2007 01:08:55, Rateup WARNING: /usr/bin/rateup Can't remove localhost_2.old updating log file 21-08-2007 01:08:55, Rateup WARNING: /usr/bin/rateup Can't rename localhost_2.log to localhost_2.old updating log file bash# mrtg mrtg.cfg 21-08-2007 01:09:55, Rateup WARNING: /usr/bin/rateup Can't remove localhost_2.old updating log file bash# mrtg mrtg.cfg bash# 4. Tricky Part Graph updates! Well, I'm a Webmin lover- mean I'm mad about it! I wrote a small file called start.pl kind alike my NT version, but a little different code- system 'LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg'; For Debian Servers use the following Command- LANG=C /usr/bin/mrtg /etc/mrtg.cfg' Saved the file in /etc/mrtg Now went back to Webmin SYSTEMS > SCHEDULED CRON JOB > CREATE A NEW SCHEDULED CRON JOBS Execute Cron Jobs as- root Active- Yes Command- /etc/mrtg/start.pl When to execute- Times & date selected below > Selected '5' in minitues section, rest are kept as default. click 'create' once. You're done! Your graphs will be updated in every 5 mins. CHIAO!!!! 5. Indexmaker You then need to make an index file which contains a list of all of your interfaces. Issue the following command (for a Debian): # indexmaker /etc/mrtg.cfg –columns=1 –output /var/www/mrtg/index.html Configurations (Linux)