Recently out broadband usage seems to have gone up quite significantly. This, naturally, has been blamed on me. And the Mac. As Min put it “this only became an issue since the mac came into the house!”.

Now you can log into the web interface of the Voyager and get the bytes since it connected. You can also reset some network traffic counters in Status -> Traffic Stats, but none of these really give you a feel for whats happening over time. Enter MRTG. I’ve been using MRTG to monitor traffic on interfaces since college and it’s very good at it. By default it will communicate with a device by SNMP, however the Voyager does not appear to have an SNMP daemon.

Thankfully MRTG can also execute a command to get its data.

You can log into the Voyager using ssh with the admin user and your admin password. This gets you to a very basic shell but one thing you can run is ifconfig which will report on the network interfaces in the box including their TX and TX byte counts.

There doesnt appear to be an easy way to set up public key authentication with the voyager so I fell back on some old school tricks for automating logins – perl & expect.

This expect script will log into the Voyager and get your ifconfig output:

#!/usr/bin/expect -f
spawn ssh admin@IP.OF.YOUR.ROUTER
expect "password:"
sleep 1
send "YOUR-PASSWORD\n"
expect "> "
sleep 1
send "ifconfig\n"
expect "> "
send "logout\n"

Next we need to grab the counters from there in a way that MRTG will understand. That is the recieved count on the first line, the transmitted count on the second, uptime is the third and the name is the fourth (mrtg docs). I just use the first and second. ppp_8_35_1 is the interface I need on my router, yours may be different. This perl script calls the expect script above to get the data.

#!/usr/bin/perl

my $flag=0;

@op=`/rusr/local/bin/bt.expect`;

foreach $_ (@op) {
    if ($_ =~ /ppp_8_35_1/ ){
        $flag=1;
        next;
    }

    if ($flag == 1 && $_ =~ /RX bytes:(\d+).*TX bytes:(\d+)/){
        print $1."\n";
        print $2."\n";
        print "0\n";
        print "0\n";
        last;
    }
}

Next we need a configuration file for MRTG. Mine is below. The various options are explained in the mrtg docs

EnableIPv6: no
WorkDir: /var/www/mrtg

Interval: 5

Title[ppp]: Network traffic (ppp)
PageTop[ppp]:
<h1>Network traffic (ppp)</h1>
Target[ppp]: `/usr/local/bin/gettraffic.pl`
Unscaled[ppp]: n
WithPeak[ppp]: ymw

It’s the just a matter of setting up a cron job for MRTG to get the data every 5 minutes:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/mrtg /usr/local/etc/bt.cfg > /dev/null 2>&amp;1

Over the course of a few hours you’ll see the patterns in your usage:
mrtg graph

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>