Thursday, December 9, 2010

Simple network usage tracking with vnstat

If you use Linux, you can use vnstat to track your network usage.
Install vnstat using
sudo apt-get install vnstat
then configure it to monitor a network interface
sudo vnstat -u -i
you can find your network interface name using ifconfig or ip addr command. In my case its eth0

Now to see your network usage issue vnstat command

to view daily, weekly or monthly stats you can use -d, -w or -m switches with vnstat respectively i.e vnstat -m
To reset all the counters to zero you will need to delete the interface's database with vnstat and then recreate it. Use the following command for this purpose
rm /var/lib/vnstat/<interface>; vnstat -u -i <interface>
Please note that vnstat is not a packet sniffer, it simply uses the network stats exposed by kernel. This means there is  non-internet network traffic on your interface e.g file sharing, network gaming or etc than it will also be included in the stats. You can use vnstat as bandwidth monitor if you use a dedicated interface for internet usage like 3g usb modem.

No comments: