Home » Configs » Simple MRTG

Simple MRTG

mrtgMRTG (The Multi Router Traffic Grapher) is a application to graph data. It is designed to graph network devices through put and loads, but can be tweaked to graph anything that you can get a numeric value for.


  • Apache or other web server. I use apache for this tutorial. (apt-get install apache or apt-get install apache2)
  • snmp configured network device (we call our network device myrouter in this example, call yours by the hostname of the device)
  • IP address of network device (myrouter=

First let’s get MRTG installed. I use a Debian based linux distro (debian, ubuntu and kubuntu), but there are MRTG packages available for almost every conceivable OS.

Debian uses apt-get:

apt-get install mrtg

Now that we have mrtg installed we need to create the directories we’ll be working with:
I like to keep my configs in an easy to remember location like /opt/mrtg:

mkdir /opt/mrtg

We also need a place to store the html files and images generated by mrtg. Note: “mkdir -p” just allows us to create a directory and any prerequisite directories. Since /var/www/mrtg didn’t exist, we couldn’t create this path without first creating it, so the -p tells mkdir to go ahead and create mrtg as well as it’s sub-directory myrouter.

mkdir -p /var/www/mrtg/myrouter

Now we need to have mrtg create a config file for our device. MRTG comes with a suite of programs the one we use to “model” our network device is called “cfgmaker”. If the command line below you see the snmp community string “public“, this is usually the default. I recommend that you do not ever use public, instead use something strong like “N3twork93821” or “0231Dev1c3001

The command for cfgmaker can be as simple as this:

cfgmaker –global ‘WorkDir: /var/www/mrtg/myrouter’  –output /opt/mrtg/myrouter.cfg public@

I tend to throw some extra options in to the mix because I like some customizations:

cfgmaker –global ‘WorkDir: /var/www/mrtg/myrouter’ -global ‘Options[_]: bits,growright’ –output /opt/mrtg/myrouter.cfg public@

Now check out the file /opt/mrtg/myrouter.cfg, it should contain lots of data points and OIDs. If all went well we should be able to move on to the next phase. If you have issues, verify that you have connectivity to the device on port 161/udp and that you have the correct snmp community string.

Assuming that cfgmaker was able to create a valid config file we need to run indexmaker. Indexmaker creates the html file that will display the graphs.
indexmaker /opt/mrtg/myrouter.cfg>>/var/www/mrtg/myrouter/index.html

Indexmaker will generate errors if the myrouter.cfg file isn’t correct or was not created properly.

Now run mrtg a few times against your myrouter.cfg file, run it until you stop seeing errors. Errors are normal as mrtg will complain about missing log files, since it’s never run it doesn’t have any.

mrtg /opt/mrtg/myrouter.cfg
/usr/bin/mrtg /opt/mrtg/myrouter.cfg

in newer versions of linux it might even require this:

LANG=C /usr/bin/mrtg /opt/mrtg/myrouter.cfg

Once the errors have disappated you can add the command line to cron to run every 5 minutes:
I typically add it to my root users crontab:

crontab -e

Then add the line:

0-59/5 * * * * root LANG=C /usr/bin/mrtg /opt/mrtg/myrouter.cfg

Do this for all your hosts you want to graph, you will need to use different names for the config files, create different directories for the html files (/var/www/mrtg/myrouter, /var/www/mrtg/myrouter1, /var/www/mrtg/myrouter2, etc) and additonal lines in your crontab

0-59/5 * * * * root LANG=C /usr/bin/mrtg /opt/mrtg/myrouter.cfg
0-59/5 * * * * root LANG=C /usr/bin/mrtg /opt/mrtg/myrouter1.cfg
0-59/5 * * * * root LANG=C /usr/bin/mrtg /opt/mrtg/myrouter2.cfg

Now if you go to your webserver:


You should see some graphs. There are plenty of docs out there on mrtg to customize your implimentation, or check back, as I will be posting lots of mrtg stuff , configs and snippets.

Was this helpful?
If you found my posts interesting, or I helped you figure something out, please consider tossing me a tiny gratuity for my time, research, to help offset the web hosting/development costs or to buy me a cup of coffee.

* This post may contain affiliate links. This means that I “might” receive a tiny amount of money, if you make a purchase using one of our links. It does not cost you anything extra, and helps us defray the costs of hosting and maintaining this site.

Leave a Reply