Network: Mrtg: monitorring network interfaces(last edit: 2001-11-29)
Mrtg is a powerful tool with which you can monitor load on network interfaces.
This article will explain how you can use mrtg and snmp together to monitor
This article assumes that you have installed and configured snmpd.
You can install mrtg from '/usr/port/net/mrtg'. Mrtg runs from crontab so you won't
find a startup script after installing it. At the end of this document I will explain how
you can run mrtg from crontab but let's first configure it.
You will find a sample file in '/usr/local/etc/mrg/', it is called 'mrtg.cfg.sample'. This
file is a great recource for mrtg. Because of this it a tough document to start with so
leave it there and read it after you read this article and have a basic mrtg running.
Create a NEW file 'mrtg.cfg' and put the following in it:
PageTop[myserver]: <H2>Stats for my server</H2>
Title[myserver][ Trafic for my server
Ok let's take a closer look at the above:
This is the dir where mrtg stores it's files. It might be handy to choose one
inside your documentroot because these files are html and grafics.
This is the number of seconds used to refresh the browser. So in this
case the browser will be refreshed every five minutes.
Should be the same as the interval specified in the crontab
The following options all apply to a specific config. You can specify options for all
configs at one (a default value) by using the config name '^'.
So in this case the 'WithPeak', 'Suppress' and 'MaxBytes' apply for all configs.
By default mrtg only shows the average traffic. With this option you can
enable peaks for the year (y), month (m) and/or week(w) graphs.
With suppress you can suppress graphs. You can suppress the
graphs for year (y), month (m) and week(w) .
This is the maximum numer of bytes your interface can handle. This
option is used to ignore wrong data from snmp (e.g. 10mbit of trafic on your 2mbit
This specfies a config, a target which you want to monitor. So between the
brackets should be an unique name. After the semicollun should be the snmp
id for your interface. You can find this number by using the following command:
snmpwalk 127.0.0.1 [community] | grep [ip number]
See the 'ip.ipAddrTable.ipAddrEntry.ipAdEntIfIndex' option that number is the
number you should place behind the 'target' option. After this number there should
be a semicollum followed by your community string an add sign and your host.
You can also count the entries in the output of 'ifconfig -a' but I'm not sure that this
is always the correct number.
The last two options should speak for themselfve.
First test it by entering the following command on the command line:
If the files are created in the dir you specified in 'WorkDir' and they are viewable
with a webbrowser then you have succeeded in setting up mrtg. Now it would be
nice to update these stats automaticly. You can do this by creating a crontab entry.
Type 'crontab -e' as root.
Type in the following line (remember it is vi thus is ESC-i, ESC-wq etc).
*/5 * * * * /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg
This will run mrtg each five minutes and thus update your stats.
Click here to go back to the index.