I always wanted to monitor my private network with an open source tool. Since I knew some nice statistics, e.g. from the DE-CIX (printed with RRDtool) or from the Uni-Gießen (generated with MRTG), I had the idea of installing such a system by myself. Luckily I found a book from Steve Shipway, called “Using MRTG with RRDtool and Routers2“, which actually disappointed me because it did not offer a complete installation guide but mainly further information about fine-tuning the appropriate tools.
Therefore, I want to show a complete step-by-step installation of all the needed tools in order to monitor a network with MRTG, RRDtool and Routers2. “From scratch” means that there are no prerequisite to this installation guide except a plain Linux server (in my case a Ubuntu Linux) such as presented here. Okay, let’s go:
Preparation
In order to use all features that I explain in the next sections, the following tools must be installed on the system. Of course, all these packages can be installed step-by-step, but I think it is easier to install them at once. Here is the list:
sudo apt-get install mrtg mrtg-ping-probe rrdtool librrds-perl snmp snmpd snmp-mibs-downloader apache2 libapache2-mod-perl2 libnet-snmp-perl libgd-gd2-perl
The installation requires round about 60 packages. Attention: The installation process from MRTG asks a single question, whether or not the root user should be the only one who can read the default configuration file from MRTG (/etc/mrtg.cfg). In our scenario, this can be answered with “Yes”, which is also the default option in this question.
Webserver: Apache
We just installed the apache web server. It is already running in the background and can be tested with a browser that accesses the IP address/domain name of the server. If you see the standard “It works!” page you are right. (The following paragraph is only for further investigations on it.)
- You can see whether the apache server is running via
ps -A | grep apache
which should show a few apache2 processes. Furthermore, the commandnetstat -l
should show at least one tcp process that LISTENs on port 80 (http). If you have IPv6 enabled, another tcp6 process also LISTENs on port 80. - The configuration can be edited with
sudo nano /etc/apache2/apache2.conf
(since I am using Ubuntu. Other Linux distributions are using httpd.conf). - If you get an error message in your logs similar to this: “apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName”, you can add a line in the apache2.conf file which starts with
ServerName
, e.g., “ServerName mrtg.example.com”. - We also already installed the CGI support. In the following file an alias specifies in which directory the CGI scripts must be stored:
cat /etc/apache2/sites-available/default
. It is under “/usr/lib/cgi-bin/”.
MRTG and RRDtool
There is not much to say about the blank MRTG installation on a Ubuntu server since it already comes with a pre-configured configuration file (/etc/mrtg.cfg) and also an installed cron job which runs MRTG every five minutes. You can verify that there is a cron job installed as you should have a file called “mrtg” in the “/etc/cron.d/” directory. You can display it via
cat /etc/cron.d/mrtg. If you look at your syslog messages with
tail /var/log/syslogyou should see a few lines similar to the following:
Jun 4 20:40:01 jw-nb10 CRON[9722]: (root) CMD (if [ -x /usr/bin/mrtg ] && [ -r /etc/mrtg.cfg ] && [ -d "$(grep '^[[:space:]]*[^#]*[[:space:]]*WorkDir' /etc/mrtg.cfg | awk '{ print $NF }')" ]; then mkdir -p /var/log/mrtg ; env LANG=C /usr/bin/mrtg /etc/mrtg.cfg 2>&1 | tee -a /var/log/mrtg/mrtg.log ; fi)
Similarly, the MRTG log is under
/var/log/mrtg/mrtg.log.
We must create some folders in order to store our configuration and rrd files. I decided to store the configs under the /etc folder while the rrd files under the /var folder:
sudo mkdir /var/mrtg #for rrd directory sudo mkdir /etc/mrtg #for config files
Note that RRDtool itself needs no further configuration since it is always used from Routers2 directly and thus needs no specific configuration.
Routers2.cgi
At first, the routers2.cgi package must be downloaded from here. Extract it, cd into the folder and start the installation:
tar xfv routers2-v2.22.tar.gz cd routers2-v2.22/ sudo perl install.pl
During the installation, several questions are asked and can be answered as follows. (Note that these are only my suggestions! Answer the questions to your needs. The following text only shows the relevant lines):
Document root? /var/www CGI directory? /usr/lib/cgi-bin MRTG config directory? /etc/mrtg MRTG files [*.cfg]? RRD directory [/tmp]? /var/mrtg Perl executable [/usr/bin/perl]? Configuration file [/var/mrtg/routers2.conf]? Activate routingtable extensions [no]? 'usebigk' option [mixed]? no auth option [none]? Caching option [no]? Can I mail [no]? INSTALLING SOFTWARE Perl is : /usr/bin/perl MRTG files : /etc/mrtg/*.cfg RRD files : /var/mrtg Doc root : /var/www CGI bin : /usr/lib/cgi-bin Config file : /var/mrtg/routers2.conf Routingtable: INACTIVE Compact page: ENABLED Caching : DISABLED 'usebigk' : no Auth option : NONE Mail Steve : no Other options can be set later by modifying the Config file Continue to install [no]? yes
After this installation process, the configuration file for routers2.cgi can be modified with
sudo nano /var/mrtg/routers2.conf. I suggest the following changes in the file: (Refer to the excellent notes in the file itself to fully understand all these settings.)
charset = utf-8 #Since otherwise the degree symbol ° isn't displayed correctly actuals = yes #Show actual values in a popup defaulttarget = summary #Show the summary page first graphstyle = x3 #Show the biggest image by default graphtype = w #Show the weekly graph by default percentile = yes #Percentile calculation sorder = l2 l2D x3 x3D #Offer only the huge images showtotal = yes #A total line on the incoming and outgoing graphs compact = no #I am not using the compact graphs. Maybe you want to... daystart = 8 #For displaying a highlighted area for the working day dayend = 18 #Ditto windowtitle = Title #Here you can customize the title of the webpage bgcolour = #fffffff #Otherwise some targets have a purple background twinmenu = yes #Since we all have widescreen displays nowadays showfindbox = no #I am not monitoring that many devices
Modifying the Default mrtg.cfg
Open the file with
sudo nano /etc/mrtg.cfgand delete (or #comment) ALL lines. Then add the following lines which are needed for the following reasons:
#Directory in which the RRD files will be stored WorkDir: /var/mrtg #Tells MRTG to use RRD instead of its own log format LogFormat: rrdtool #To have multiple instances of MRTG running to immediately pass through all targets Forks: 4 #Use the configs in the mrtg subfolder (/etc/mrtg) Include: mrtg/*.cfg
First Test (Yet Without Any Devices)
With a web browser, access the following page/file:
http://<ip-address>/cgi-bin/routers2.cgi.
Since there are no monitored devices (called “targets”) yet, this blank page should look like this:

If so, you are almost done with the base installation of MRTG, RRDtool and Routers2!!! Congratulations!
You can also view the configuration verification of Routers2 when you access the following URL (of course without any targets, too):
http://<ip-address>/cgi-bin/routers2.cgi?page=verify.
Forwarding to Routers2.cgi
It is desirable to have a forwarding to the routers2.cgi if only the IP address or domain name of the server is entered. That is, even though only
http://domain.nameis entered in the browser, the routers2.cgi page should appear. This can be done by adding a few lines to the index.html under
/var/www/index.html: Between the
<html>and the
<body>tag, the following lines should be inserted, of course with the correct domain name:
<head> <meta http-equiv="refresh" content="0; URL=http://domain.name/cgi-bin/routers2.cgi/"> </head>
From now on, the web page automatically redirects to the routers2.cgi page after a few milliseconds.
Adding Devices/Targets
Since we now have a complete MRTG with RRDtool and Routers2 installation, we can add several devices to monitor, e.g., network routers and switches, firewalls, servers, and/or even other interesting values to monitor, such as ping-times to a remote server, temperature values, firewall statistics, etc. I will explain the adding procedure for various targets into MRTG in later posts. However, here comes a rough overview:
Querying SNMP values
The first step is always to activate SNMP on the appropriate device. I recommend to use different community strings (i.e., passwords) for every single device! After that, the querying of SNMP can be tested from the Linux server with the tools from snmp, e.g., snmpwalk. Here is an example with the first few lines from requesting a Juniper SSG firewall:
weberjoh@jw-vm01:~$ snmpwalk -v 2c -c krmbd5aPfQ 172.16.1.1 .1.3.6 iso.3.6.1.2.1.1.1.0 = STRING: "SSG5-Serial-WLAN version 6.3.0r16.0 (SN: ---, Firewall+VPN)" iso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.3224.1.32 iso.3.6.1.2.1.1.3.0 = Timeticks: (57520000) 6 days, 15:46:40.00 iso.3.6.1.2.1.1.4.0 = STRING: "johannes@webernetz.net" iso.3.6.1.2.1.1.5.0 = STRING: "fd-wv-fw01" iso.3.6.1.2.1.1.6.0 = STRING: "Serverraum" iso.3.6.1.2.1.1.7.0 = INTEGER: 72 iso.3.6.1.2.1.2.1.0 = INTEGER: 24
For gathering information about the MIBs that the device supports, the brilliant MIB Browser from iReasoning can be used. It is free for personal use an can be downloaded here. It uses a GUI, can load several MIBs and is able to request the whole SNMP tree via “Get Subtree”. Really good! Here is a screenshot with the output of the NetscreenVpnMonitor MIB:
With these information, precise SNMP OIDs can be queried with MRTG, etc.
Building the MRTG/Routers2 Configuration
Finally, the *.cfg files for MRTG/Routers2 must be created. The tool cfgmaker which ships directly with MRTG can be used for the basic gathering of interfaces of routers and switches, such as:
cfgmaker --snmp-options=:::::2 --output=filename.cfg qYMJOYSx1F@172.16.1.1
Note that you can use host templates and interface templates with cfgmaker. [Comment by Steve added here:] “These are scripts that add additional Targets either on a per-device or per-interface basis. For example, the correct host template will add Targets to monitor CPU, Memory, disk space, and so on at the same time as creating all the Interface targets. You can download some templates that work with most hosts and devices from http://www.steveshipway.org/cfgmaker.”
Also note that I wrote several posts about adding other devices to MRTG/routers2. Use this category to search for them on my blog.
MRTG on the Raspberry Pi?
Since the RPi is quite popular these days, it would be a good use case to run MRTG and the other programs on it. I tried it (Model B) and my short summary is: Everything runs without problems – but it is really slow. I have monitored a few switches with 24 ports each, and the RPi took a few seconds for every refresh of the summary page. This is because the Routers2.cgi generates all RRD images on the fly which consumes lots of CPU power. That is: I stopped running MRTG on the RPi because it was simply to slow.
Okay, finished for today!