====== MRTG ======
The ''Multi Router Traffic Grapher'' is a powerful tool to generate graphs for
various kinds of system information. The most commonly used backend is snmp,
whose network ability actually is the reason for the ''M'' in ''MRTG''. Besides
using snmp as the data source, one can run regular scripts outputting data to
be graphed. The following shows the local setup for nwl.cc.
===== Installation =====
Easy as eatin' pancakes: simply install ''MRTG'' and your preferred snmp
implementation (''net-snmp'' in my case).
===== Configuration =====
Basically, the following things are needed:
* a single ''MRTG'' config for each graph to generate
* a cron job to update the graphs values
* a destination directory for the graphs and the //index.html// (auto-generated)
==== MRTG Configurations ====
Create the directory ///etc/mrtg//, which will contain all the configs.
There are two ways to get a config for MRTG: either using ''cfgmaker'' (shipped
with MRTG) or create by hand, which of course is the more flexible way.
''cfgmaker'' on the other hand is used best when creating graphs for network
interfaces, as the output is quite nice without much effort necessary.
To generate configs for all local NICs, use something like this:
cfgmaker --output=/etc/mrtg/traffic.cfg --ifdesc=ip --ifref=descr \
--global "WorkDir: /var/www/nwl.cc/htdocs-secure/mrtg" \
--global "Options[_]: bits,growright" public@localhost
Note that this will generate the config as ///etc/mrtg/traffic.cfg//, and
assumes that the output directory for the graphs is
///var/www/nwl.cc/htdocs-secure/mrtg//. Also this obviously uses snmp as
backend, so won't be usable without an snmpd running locally.
As sample for a manually created MRTG config, this one is used to monitor CPU
load:
WorkDir: /var/www/nwl.cc/htdocs-secure/mrtg
LoadMIBs: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
Target[localhost.cpu]:ssCpuRawUser.0&ssCpuRawUser.0:public@localhost
+ ssCpuRawSystem.0&ssCpuRawSystem.0:public@localhost
+ ssCpuRawNice.0&ssCpuRawNice.0:public@localhost
RouterUptime[localhost.cpu]: public@localhost
MaxBytes[localhost.cpu]: 100
Title[localhost.cpu]: CPU Load
PageTop[localhost.cpu]: Active CPU Load %
Unscaled[localhost.cpu]: ymwd
ShortLegend[localhost.cpu]: %
YLegend[localhost.cpu]: CPU Utilization
Legend1[localhost.cpu]: Active CPU in % (Load)
Legend2[localhost.cpu]:
Legend3[localhost.cpu]:
Legend4[localhost.cpu]:
LegendI[localhost.cpu]: Active
LegendO[localhost.cpu]:
Options[localhost.cpu]: growright,nopercent
Notes:
* Adding MIB descriptions to the ''LoadMIBs'' parameter allows for using symbolic names in the ''Target'' description. **BUT** there is no support for auto-loading included MIB descriptions by the specified ones, so the desired description has to be parsed manually for any ''INCLUDE'' directives and the mentioned descriptions have to be added right before the desired one to the ''LoadMIBs'' option.
==== MRTG Cron Job ====
The cron job is quite simple to create since we assume all active configs are kept inside ///etc/mrtg//, ending with //.cfg//:
#!/bin/sh
mrtg="/usr/bin/mrtg"
for conf in /etc/mrtg/*.cfg; do
$mrtg ${conf}
done
You can save this script where you want to, I just saved it in ///etc/mrtg//, too.
To make the job active, add the following line to ///etc/crontab//:
*/5 * * * * /etc/mrtg/cronjob.sh 1>/dev/null
(replacing the path to and name of the script from above, if necessary).
==== Preparing The Output Directory ====
First, the graphs initially have to be created. This is done by simply executing the cron job three times manually. Then a simple call to ''indexmaker'' should to the rest:
indexmaker --output=/var/www/nwl.cc/htdocs-secure/mrtg/index.html \
--title="System Graphs Powered By MRTG" \
--sort=name --enumerate /etc/mrtg/*.cfg
===== Links =====
* [[http://forums.gentoo.org/viewtopic-t-105862.html|Gentoo Howto: SNMP & MRTG made in easy]]