GIT – MRTG is the The Multi Router Traffic Grapher. MRTG is used for monitoring the network traffic of your routers via SNMP. It is able of producing nice graphs showing you the traffic load of your routers and devices.
Table of Contents
- Installing MRTG
- Configuring the SNMP daemon
- Configuring Apache
- Configuring MRTG
- Starting Apache and MRTG
MRTG is the The Multi Router Traffic Grapher. MRTG is used for monitoring the network traffic of your routers via SNMP.
It is able of producing nice graphs showing you the traffic load of your routers and devices.
Besides routers, MRTG is capable of monitoring any device that has SNMP support.
Please check the official web site of MRTG for a demo, and more information regarding MRTG.
This setup has been tested and works fine on a FreeBSD-8.1 system and MRTG version mrtg-2.17.0,1
- root access or sudo rights
- You have installed and configured Apache server already. If you don’t have Apache installed on your FreeBSD system, please refer to the following handbook, which explains how to install Apache under FreeBSD.
In this handbook we will be installing MRTG using the FreeBSD Ports Collection.
First make sure that your Ports tree is updated and then proceed with the command below, which will install MRTG on your system:
Once the installation is over you should see something similar:
Now that we have MRTG install, let’s continue with the configuration of the SNMP daemon and MRTG itself.
Configuring the SNMP daemon on the machines to be monitored
In this step we will configure the SNMP daemon on the FreeBSD machines to be monitored.
You can skip this step, if your machines or routers already have configured SNMP daemons.
Here we are going to use the SNMP daemon that comes with the base FreeBSD system – bsnmpd(1).
You might also want to install a more extensible SNMP daemon like net-mgmt/net-snmp, but this is not in the scope of the current handbook.
The configuration for bsnmpd(1) resides is in the /etc/snmpd.config file.
Please refer to the manual page for bsnmpd(1) for more information about the different options and explanation of them.
In the configuration we are only going to change a couple of things, so again, please refer to the manual page of bsnmpd(1) for more information regarding the rest of the configuration options.
In the above configuration we set the read community to bsnmpd
To enable bsnmpd(1) during boot-time, add the following lines to your /etc/rc.conf file.
Now let’s start the SNMP daemon:
You will need to configure the SNMP daemon on each machine you want to monitor. Once you are ready with that, please proceed with the next step.
Configuring Apache for MRTG
In this step we will configure the default Apache vhost to point to MRTG
Assuming you have read the handbook for installing and configuring Apache, we will now make some minor changes to ourhttpd-vhosts.conf file, so that our default Apache vhost points to MRTG.
And here is mine httpd-vhosts.conf file, feel free to make the needed changes, so that it reflects your setup.
In the above example configuration our Apache vhost is monitor.example.org and it’s document root reside in /usr/local/www/mrtg
We also need to create the needed folders and set proper permissions for them:
Now we can go to the next step, where we will configure MRTG and add the hosts to be monitored by MRTG.
Now let’s add the hosts that we want to monitor to MRTG. For that purpose we are going ot use cfgmaker(1)
Using the above command we are adding two hosts that will be monitored by MRTG – host1.example.org and host2.example.org.
We are also defining some global options like WorkDir, Options and WithPeak and the output file is set to /usr/local/etc/mrtg/mrtg.cfg – the default MRTG configuration file
Remember to substitute the community for each host to the proper one which you defined in the SNMP configuration.
Please refer to the man page of cfgmaker(1) for more information about the different options that you may pass to cfgmaker(1)
cfgmaker(1) pulls information from the SNMP device(s) about it’s interfaces and puts this into the file specified by the –output option.
The output file will contain information about every interface of the SNMP device that was found – some of these interfaces as you may notice will be commented, like for example the loopback interface, and all the interfaces that are currently down.
Now open the /usr/local/etc/mrtg/mrtg.cfg config file and remove all those interfaces that you do not want to monitor. It will make the file cleaner and much easier to read as well.
Here’s mine mrtg.cfg file, that contains only one interface for each host we’ve added using cfgmaker(1):
Once you are ready adding all your hosts, we can then use indexmaker(1), so that we have a nice index page showing you the graphs for the different hosts, which you can simply click on.
So, let’s create the index page. Please refer to indexmaker(1) manual page for more information about the different options that are supported by indexmaker(1):
Now let’s create the log file for MRTG.
Now that we have everything installed and configured we can start up Apache and MRTG.
Starting Apache and MRTG
First let’s test the Apache configuration and then start it:
The output from the above command should be Syntax OK, otherwise you will need to go back and check for errors in your Apache configuration.
Now we can start MRTG. First we need to run MRTG manually, so that it creates the web pages and graphs.
Executing the below command will result in errors when you run it the first 2-3 times, so just keep in mind that this is OK. Just execute the below command 2-3 times, until all error messages are gone. If they keep showing after 2-3 times executing the command, this probably means that you’ve made some errors in your mrtg.cfg file.
Running MRTG manually after this point is not recommended, because you will need your graphs to be updated in a certain period of time, so it is best to put it running as a cron job each 5 minutes.
To do that simply add the following lines to your /etc/crontab file, so that MRTG polls your routers each 5 minutes:
And that’s it! Now open your Apache vhost at monitor.example.org in order to see your graphs.