This guide will you get started with MRTG on CentOS 5. It is by no means a complete reference. A complete reference can be obtained from Tobi Oetiker’s website.


Install MRTG

yum -y install mrtg

Optionally install snmpwalk and snmpget

yum -y install net-snmp-utils


Before going any further with this you will need to gather some information from your devices. You may have to obtain a MIB for your device and or do some research to figure out which OID’s to use. The snmpget and snmpwalk commands will help as well.

Configuration Files

The MRTG package will create a sample configuration file, crontab file, and Apache configuration file.


/etc/mrtg/mrtg.cfg – Initial Sample

Once you have the OID information you can begin editing your mrtg.cfg file. Simply uncomment the lines and modify them to point to the device you are monitoring. The default file has a sample host to get you started.

HtmlDir: /var/www/mrtg
ImageDir: /var/www/mrtg
LogDir: /var/lib/mrtg
ThreshDir: /var/lib/mrtg
#Target[r1]: 2:[email protected]
#MaxBytes[r1]: 1250000
#Title[r1]: Traffic Analysis

Stats for our Ethernet

/etc/mrtg/mrtg.cfg – Extended Sample

Here is an extended sample mrtg.cfg that will gather the port throughput on a Linksys router running DD-WRT. In this example the maxbytes field has been changed to a global setting by using the underscore. Additional global options are defined so that graph grows from the right and displays bits instead of bytes. Each port is configured as a separate target. The input and output OIDs are specified using their symbolic names, followed by the community string and management IP address.

HtmlDir: /var/www/mrtg
ImageDir: /var/www/mrtg
LogDir: /var/lib/mrtg
ThreshDir: /var/lib/mrtg
MaxBytes[_]: 1250000
Options[_]: growright, bits

Target[Linksys_Port_1]: ifInOctets.1&ifOutOctets.1:[email protected]
Title[Linksys_Port_1]: Linksys Port 1 Throughput

Linksys Port 1 Throughput

Target[Linksys_Port_2]: ifInOctets.2&ifOutOctets.2:[email protected] Title[Linksys_Port_2]: Linksys Port 2 Throughput PageTop[Linksys_Port_2]:

Linksys Port 2 Throughput

Target[Linksys_Port_3]: ifInOctets.3&ifOutOctets.3:[email protected] Title[Linksys_Port_3]: Linksys Port 3 Throughput PageTop[Linksys_Port_3]:

Linksys Port 3 Throughput

Target[Linksys_Port_4]: ifInOctets.4&ifOutOctets.4:[email protected] Title[Linksys_Port_4]: Linksys Port 4 Throughput PageTop[Linksys_Port_4]:

Linksys Port 4 Throughput

Target[Linksys_Port_5]: ifInOctets.5&ifOutOctets.5:[email protected] Title[Linksys_Port_5]: Linksys Port 5 Throughput PageTop[Linksys_Port_5]:

Linksys Port 5 Throughput

Target[Linksys_Port_6]: ifInOctets.6&ifOutOctets.6:[email protected] Title[Linksys_Port_6]: Linksys Port 6 Throughput PageTop[Linksys_Port_6]:

Linksys Port 6 Throughput

Target[Linksys_Port_7]: ifInOctets.7&ifOutOctets.7:[email protected] Title[Linksys_Port_7]: Linksys Port 7 Throughput PageTop[Linksys_Port_7]:

Linksys Port 7 Throughput

/etc/mrtf/mrtg.cfg – Using cfgmaker

It is also possible to have MRTG automatically build a configuration file for your device.

cfgmaker [email protected] > /etc/mrtg/mrtg.conf


After the configuration has been saved MRTG will start building the rrdtool log files and basic HTML pages. You can run the poller commands manually if you’re impatient or you want to troubleshoot.

export LANG=C 
export LC_ALL=C 
/usr/bin/mrtg /etc/mrtg/mrtg.cfg --lock-file /var/lock/mrtg/mrtg_l --confcache-file /var/lib/mrtg/mrtg.ok

/etc/httpd/conf.d/mrtg.conf – Apache Configuration

After several minutes pull up your site in your favorite browser.

By default the MRTG Apache configuration will only allow localhost to view the URL. If you need to access the URL from another machine just modify the MRTG Apache configuration file and restart Apache. This example only has the Alias definition.


Alias /mrtg /var/www/mrtg

#    Order deny,allow
#    Deny from all
#    Allow from
#    Allow from ::1
#    # Allow from

Restart Apache after making the change.

service httpd restart

Creating The Index Page

There will be no index.html. You can use indexmaker to create this. Either add this to the crontab or just run it whenever you make changes to your mrtg.cfg.

indexmaker --output=/var/www/mrtg/index.html /etc/mrtg/mrtg.cfg

Now you should be able to pull up in your favorite browser to view the graphs.


  • Official MRTG Site RRDTool Guide MIB Downloads