There are many command-line utilities in the Unix / Linux world that collect network traffic statistics for a chosen interface.
vnstat is different because statistics are collected permanently. It keeps the data in files so traffic monitoring is resumed at reboot. vnstat can be useful in situations when you need to know the exact amount of traffic that goes through the interface for a period longer than the computer is on. For example when you have a mobile 3G internet connection or an xDSL connection that has traffic limit per month, then you can easily check how much traffic you generated.
vnstat can be run without root privileges because it collects data from the kernel’s proc filesystem. It doesn’t have a daemon service, it is simply run by cron periodically. In Debian, the installation creates a cron job where a vnstat -u command is run every 5 minutes:
Initially, you have to create the database with this command:
1
vnstat -u -i wlan1
After creating the database, the statistics can be viewed by running vnstat without any further parameters. Thanks to the cron job, the statistic is updated every 5 minutes. It even remembers the interface name to list:
Permanent network traffic statistic that is not forgotten.
Very lightweight solution, no daemon service is running in the background (automatically run from cron periodically).
Easy to install and use. In vnstat, everything can be done from the command line and it clearly shows how many megabytes have you send/receive in a given day or month.
Cons:
Internet or remote traffic cannot be separated from local network traffic if it all goes through the interface being monitored.
It works for a single host, but it doesn’t scale very well. If you need to monitor a lot of hosts and need detailed graphs, there are better alternatives, such as munin or ganglia.
Availability
There are official packages available in both “Debian”:https://packages.debian.org/vnstat and “Ubuntu (Universe)":https://packages.ubuntu.com/vnstat for a long time now.