Monitoring your bandwidth usage with vnstat
Posted by Steve on Thu 12 Jan 2006 at 12:43
There are many occasions where it is useful to have an idea of your bandwidth usage, perhaps to know when you're going to be charged more by your ISP, or perhaps just as part of general monitoring. The vnstat tool is a simple means of doing just that.
vnstat is a console based tool which is simple to setup and capable of monitoring your incoming and outgoing bandwidth usage.
The output allows you to see the bandwidth you've used in a variety of ways, such as by hour, by day, etc. As a bonus it doesn't require the use of root privileges once it has been installed.
The Debian package is contained in both Sarge, Testing and Sid, and can be installed via the following command: root@lappy:~# apt-get install vnstat
Once installed you'll need to initialise the database the system uses for recording your traffic details. The tool uses one database for each network interface you wish it to monitor. (These are not real databases, just text files located in the directory /var/lib/vnstat.)
Since my system only has a single network interface I just need to run:
root@lappy:~# vnstat -u -i eth0
(You might wish to repeat this changing eth0 for each interface you wish to monitor.)
Once the text database(s) have been initialised you're ready to monitor your bandwidth usage. The package installs a cronjob which will update the database every five minutes.
Once you've left the system alone for a while to quietly collect the data you can view it using one of the reporting modes. The most simple way of doing so is to just invoke the command with no arguments:
skx@lappy:~$ vnstat Database updated: Thu Jan 12 12:35:01 2006 eth0 received: 76.17 MB (87.4%) transmitted: 11.72 MB (12.6%) total: 87.90 MB rx | tx | total -----------------------+------------+----------- yesterday 53.66 MB | 7.69 MB | 61.36 MB today 22.50 MB | 4.03 MB | 26.54 MB -----------------------+------------+----------- estimated 41 MB | 7 MB | 48 MB
There are several different ways of viewing the bandwidth usage as we suggested earlier. These are invoked via command line arguments such as --hours, --days, etc.
This is an hourly view:
eth0 12:35 ^ t | t | t | t t t | t t t t t t | t t t t t t t t | t t t t t t t t t t t t t | t t t t t t t t t t t t t t t t t t | t t t t t t t t t t t t t t t t t t t t t t t t | rt rt rt t t t t rt t t t t t t t t t t t t t t t t -+---------------------------------------------------------------------------> | 13 14 15 16 17 18 19 20 21 22 23 00 01 02 03 04 05 06 07 08 09 10 11 12
vnstat is a useful tool for showing you the total transmitted and received network data. One drawback is that it won't show you what has been sending or receiving data - just the count of data sent. If you're looking to view more advanced network statistics you'll probably wish to use something like ntop instead.
For more details of the available output modes please see the vnstat manpage which you can read by running: