Monitoring bandwidth during peak hours

Like many ISPs in Britain, mine allows me unlimited downloads during off-peak hours but has a monthly restriction on downloads during peak hours.  Peak currently means 6pm until midnight, although next month it will be changing to 9am until 11pm.  I thought it would be a good idea to monitor how close to my quota I am, to see if this will affect me.

I found the vnstat project, which is already packaged for Fedora, and this is almost exactly what I needed.  After installing the package, I just needed to configure it:

  1. Edit /etc/sysconfig/vnstat to make sure the correct network interface is monitored.
  2. Edit /etc/cron.d/vnstat and uncomment the line that enables network interface monitoring (not sure why this comes commented out).
  3. Edit /etc/vnstat.conf and check that everything looks right. I changed the locale, but I’m not sure why it doesn’t use the system locale.  Maybe something to do with cron?

It works by gathering data from the proc filesystem and using it to update a simple database file each time it is run from cron.

The only missing piece was the ability to examine network usage during peak hours only.  I’ve sent a patch for this to the maintainer, and put a small git repository here:

git clone http://cyberelk.net/tim/data/vnstat.git

If you’re reading this from the future and that link doesn’t work, hopefully it’s because the patch has been accepted…

I can now see my actual peak usage so far, as well as the estimated total for this month.  Here’s an example of the output (not real data):

 eth0  /  monthly

   month         rx      |      tx      |   total
-------------------------+--------------+--------------------------------------
  Jul '08       1.34 GB  |   103.00 MB  |     1.44 GB   %%%%%%%%%%%%%%%%%%%%::
   (peak)      32.57 MB  |     1.71 MB  |    34.28 MB
-------------------------+--------------+--------------------------------------
 estimated     16.10 GB  |     1.21 GB  |    17.31 GB
   (peak)        384 MB  |       12 MB  |      396 MB

Posted

in

by

Tags:

Comments

9 responses to “Monitoring bandwidth during peak hours”

  1. mkwerner avatar
    mkwerner

    Hi Tim,
    Great article! Question for you – do you use this solution on a stand-alone pc or on a gateway pc? I ask because my ISP is probably going to take a similar approach in the next year or so, and I’d like a way to monitor our usage via my gateway. Not sure if this would work or not, but interesting read none the less.

    Regards,
    Matt

  2. tim avatar

    Yes, it will work on a gateway. It just monitors whichever network interface you tell it to, so pick the one that all your Internet traffic goes through.

  3. mkwerner avatar
    mkwerner

    Thanks Tim – I appreciate the response! Can’t wait to try it out.

    Cheers,
    Matt

  4. […] – bookmarked by 3 members originally found by jackbalmont on 2008-10-13 Monitoring bandwidth during peak hours http://cyberelk.net/tim/2008/07/03/monitoring-bandwidth-during-peak-hours/ – bookmarked by 3 […]

  5. Francis avatar
    Francis

    How does it work? I grepped “hour” and “peak” on your git repository and found nothing. Where should I set the onpeak/offpeak period?

    Is it possible to apply your diff to version 1.11?

    Thanks!

  6. Tim avatar

    Use the ‘Peak’ keyword in the configuration file. Here’s the comment that gets written to a new config file:

    # peak hours (e.g. 6pm-midnight: Peak 6 7 8 9 10 11)
  7. Francis avatar
    Francis

    Thanks for the info.

    Do you have a diff/patch file? I wonder if I can make it work with a recent version of vnstat on my OpenWrt router.

  8. Tim avatar

    I’ve put the result of “git diff 1.6 monthpeak” here: http://cyberelk.net/tim/data/vnstat.git/vnstat-monthpeak.patch.

  9. Francis avatar
    Francis

    Thanks for the diff. Unfortunately, source changed a lot since you did your patch and I don’t have any C skills :D. I will just continue to stop the vnstatd deamon for off peaks hours.