Basic Host Bandwidth Monitoring (Linux, BSD)

Whilst quite cool, it can also be quite important to keep a log of the bandwidth being used by a server – whether it’s because you have bandwidth limitations from a data center or ISP, whether you just want to see how much the server uses, or even to detect when something “strange” is going on, basic stats are good – you may not need a fully fledged MRTG setup with graphs though, and this is where vnstat comes in – it’s a basic text-based application, which monitors traffic in and out of a network card.

I install vnstat as a matter of course on all servers I installed – it’s light, and it’s good just to keep a log on things.

For this example, I’ve installed vnstat on an Ubuntu Server, so I’ll be using apt-get to install the package from the standard repositories:

apt-get install vnstat

Once installed, we need to initialise the database.. and in my case, it is for eth0 (you can change eth0 to whichever interface you want to monitor):

vnstat -u -i eth0

Now vnstat will start collecting stats, and you have a whole range of command line options to show different types of stats:

 -d,  --days           show days
 -m,  --months         show months
 -w,  --weeks          show weeks
 -t,  --top10          show top10

So, for example, if we do -m to show monthly stats:

 eth0  /  monthly
   month         rx      |      tx      |   total
  May '09       3.81 MB  |     1.02 MB  |     4.83 MB
  Jun '09     195.68 MB  |   198.24 MB  |   393.92 MB   %%%%%%%%%%%:::::::::::
  Jul '09     217.62 MB  |   103.79 MB  |   321.41 MB   %%%%%%%%%%%%:::::
 estimated       972 MB  |      461 MB  |     1.40 GB

You’ll notice a nice feature at the bottom of estimated use for the next month – again, this takes current/past stats, and works out roughly what it thinks will be used – so in this case, it’s predicting a big increase for July.. which looks about right, especially as it’s used 321MB already.

So, give vnstat a try – I think you’ll like it.

You can read more about vnstat on the official web site: