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:
man vnstat
[ Parent ]
[ Parent ]
[ Parent ]
As mentioned, briefly, in the article the system runs via a cronjob.
The package installs the file /etc/cron.d/vnstat with the following contents:
0-55/5 * * * * ...
This causes the main binary to be called every five minutes to update the statistics; and as such it'll survive a reboot just fine :)
[ Parent ]
[ Parent ]
iptraf and ipfm is what I used on my old p100 gateway box.
PJ
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
Well it is a database - I just wanted to make the point that it wasn't a full relational database and make sure people didn't think they needed Postgres/Mysql/sqlite/etc installed.
(I got told off in the past for not making the distinction!)
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
[ Parent ]
I find bwm is a nice way of getting a live snapshot of how much bandwidth you are using right now.
If you are just concerted about apache traffic, apachetop is good.
[ Parent ]