Getting Started With MRTG on CentOS 5

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.

Installation

Install MRTG

yum -y install mrtg

Optionally install snmpwalk and snmpget

yum -y install net-snmp-utils

MIBs & OIDs

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
/etc/cron.d/mrtg
/etc/httpd/conf.d/mrtg.conf

/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:public@myrouter.somplace.edu
#MaxBytes[r1]: 1250000
#Title[r1]: Traffic Analysis
#PageTop[r1]: <H1>Stats for our Ethernet</H1>

/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:public@192.168.0.9
Title[Linksys_Port_1]: Linksys Port 1 Throughput
PageTop[Linksys_Port_1]: <H1>Linksys Port 1 Throughput</H1>

Target[Linksys_Port_2]: ifInOctets.2&ifOutOctets.2:public@192.168.0.9
Title[Linksys_Port_2]: Linksys Port 2 Throughput
PageTop[Linksys_Port_2]: <H1>Linksys Port 2 Throughput</H1>

Target[Linksys_Port_3]: ifInOctets.3&ifOutOctets.3:public@192.168.0.9
Title[Linksys_Port_3]: Linksys Port 3 Throughput
PageTop[Linksys_Port_3]: <H1>Linksys Port 3 Throughput</H1>

Target[Linksys_Port_4]: ifInOctets.4&ifOutOctets.4:public@192.168.0.9
Title[Linksys_Port_4]: Linksys Port 4 Throughput
PageTop[Linksys_Port_4]: <H1>Linksys Port 4 Throughput</H1>

Target[Linksys_Port_5]: ifInOctets.5&ifOutOctets.5:public@192.168.0.9
Title[Linksys_Port_5]: Linksys Port 5 Throughput
PageTop[Linksys_Port_5]: <H1>Linksys Port 5 Throughput</H1>

Target[Linksys_Port_6]: ifInOctets.6&ifOutOctets.6:public@192.168.0.9
Title[Linksys_Port_6]: Linksys Port 6 Throughput
PageTop[Linksys_Port_6]: <H1>Linksys Port 6 Throughput</H1>

Target[Linksys_Port_7]: ifInOctets.7&ifOutOctets.7:public@192.168.0.9
Title[Linksys_Port_7]: Linksys Port 7 Throughput
PageTop[Linksys_Port_7]: <H1>Linksys Port 7 Throughput</H1>

/etc/mrtf/mrtg.cfg - Using cfgmaker

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

cfgmaker public@192.168.0.9 > /etc/mrtg/mrtg.conf

/etc/cron.d/mrtg

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. http://www.example.com/mrtg/linksys_port_1.html

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.

/etc/httpd/conf.d/mrtg.conf

Alias /mrtg /var/www/mrtg

#<Location /mrtg>
#    Order deny,allow
#    Deny from all
#    Allow from 127.0.0.1
#    Allow from ::1
#    # Allow from .example.com
#</Location>

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 http://www.example.com/mrtg in your favorite browser to view the graphs.

Links

TipsAndTricks/MRTG (last edited 2008-09-12 16:57:29 by ChrisNaude)