How To Get Data For Mrtg Without Running SNMP Daemon?
5 Apr2006

Plotting traffic graphs is one of the most popular UNIX admin tasks. ;-) Mrtg is a great tool and it is widely used for plotting traffic graphs. It can be easily set up to plot statistics for any SNMP-enabled device (including Linux servers running snmpd). But sometimes we can not setup snmp daemon in Linux server because of small amount of memory or because of some another reasons. How we can plot our favourite graphs in such cases?

When I have installed my home server to connect my home network to Internet, there was too small amount of RAM and spending free memory to run snmpd was not possible. As a solution I have created small Perl script, that can get information from /proc/net/dev and pass it to mrtg script.

If you want to try this script, you need to make following simple steps on your server:

  1. Download my script, rename it to get_if_stats.pl and put it to /usr/local/bin directory on your server.
  2. Make it executable:

    # chmod +x usr/local/bin/get_if_stats.pl
    

  3. Add new entry to mrtg.conf (example is for eth0 interface):

    Title[new_graph]: World channel (eth0)
    PageTop[new_graph]: <h1>Some new mrtg graph (eth0)</h1>
    Target[new_graph]: `/usr/local/bin/get_if_stats.pl eth0`
    MaxBytes[new_graph]: 100000000
    

That is all! Now you can plot graphs for any interface without running huge snmp daemons in your server memory