Painless Debian Traffic Graphs

Getting graphs of the traffic into and out of a computer running Linux shouldn’t be a headache, but it frequently is. MRTG is the old standard. The documentation leaves a bit to be desired, and configuration can be a nightmare. All the cool kids use Cacti, anyway, which is newer and better and has a lot more bells and whistles.

However, Cacti is still a pain to configure, requires MySQL, and it doesn’t seem to like to play well with webservers other than Apache. That’s fine, perhaps, if you want bandwidth graphs for a plain old LAMP hosting box, but irritating when all you want is traffic stats for a mailserver, IRC server, shoutcast server, gameserver… or anything else that doesn’t already require a big, bloated webserver and SQL. Too, it requires you to install SNMP and get it working, which can be more trouble than it’s worth.

All the instructions on the web assume you want to monitor and graph everything on your machine – load, temperature, disk usage, and everything else. Don’t get me wrong, MRTG and Cacti are great programs, and can do a staggering amount of cool stuff. If, like me, all you want is a record of bandwidth use for the entire server (or, at least, one physical interface), there’s a super-simple way to get it, without messing around with SNMP permissions and the thousands of things that can and do go wrong with Cacti for no apparent reason, or MRTG’s configuration “helpers”.

The trick is a program called mrtg-ip-acct, and it’s included with Debian, at least, as part of the mrtgutils package. Setting it up couldn’t be easier, either. Install the mrtg and mrtgutils packages –

~# apt-get install mrtg mrtgutils

Debian will probably prompt you to install various libraries; that’s fine. Once they’re installed, you really only need to do two things. One is to create a working directory for the MRTG graphs and output; it should probably be under your webpage root (/var/www on my machines running Lighttpd.) For instance:

~# mkdir /wherever/your/webpages-are/mrtg

Once that’s done, you’ll need to edit the MRTG configuration file, which is probably /etc/mrtg.cfg. Delete whatever is in there, if anything, and replace it with the following:

WriteExpires: Yes
workdir: /wherever/your/webpages-are/mrtg

forks: 2
refresh: 300
interval: 5
runasdaemon: yes

Target[index]: `/usr/bin/mrtg-ip-acct eth0`
XSize[index]: 600
YSize[index]: 180
MaxBytes[index]: 1310720
Title[index]: eth0
PageTop[index]: Traffic Analysis for
WithPeak[index]: w
Options[index]: growright, bits

Obviously, you need to put in the correct absolute path to where you want the graphs to be, and if your interface isn’t eth0, you’ll want to change that. (This works fine even on VPS machines, where the interface is something like “venet”.) You can see the MRTG page for details on what all the configuration options do; basically this will graph the traffic, in average bits per second, in and out of a 10Mbps connection, at five-minute intervals. The part in [brackets] is the internal interface name, and controls what the page and graphs for the interface are called. By using [index], it somewhat handily creates your traffic display page as /var/www(or whatever)/mrtg/index.html.

Once you’ve got that saved, fire up MRTG:

~# mrtg

You’ll see a few errors the very first time you run it, as it tries to move files that don’t exist yet; that’s normal. Wait fifteen minutes, and point your browser to http://www.yourwebsite.tld/mrtg/ , and you should see four traffic graphs and a bunch of information.

I use this to monitor traffic on a couple of machines that aren’t webservers, running barebones copies of lighttpd, and it works wonderfully.

If only everything in life were so easy.

Published in: Geekiness, General | on April 15th, 2007| 5 Comments »

Both comments and pings are currently closed.


  1. On 11/21/2007 at 1:22 pm Happy Said:

    Just that??!?!?! And it works too!
    I love Debian 🙂

  2. On 10/19/2013 at 7:46 am tony cooper Said:

    It doesn’t work for me.
    I just get “Index of /mrtg” when i visit the page in the browser.

  3. On 10/19/2013 at 8:35 pm tony cooper Said:

    It worked.
    If you get: “Index of /mrtg” when you visit the page in the browser, then run it as root.

  4. On 10/19/2013 at 8:42 pm tony cooper Said:

    any idea why this is only displaying incoming traffic?
    outgoing traffic is always 0, even though my server is moving 1TB out per day…

  5. On 8/25/2014 at 10:56 am Alberto Reyes Said:

    Wow!!! I like the way to make it simple!!! 10 minutes configuration of 3 interfaces with no experience of mrtg!!!!
    Thanks a lot