Bandwidth monitoring with vnStat


Author: Sukrit Dhandhania

If you want to monitor and manage your Internet bandwidth, perhaps to make sure your ISP is not overbilling you, try vnStat, an open source, Linux-based application that gives you a clear picture of your bandwidth usage. This command-line application is simple to install and easy to use.

VnStat offers binary packages for the Debian distribution on its site, and Dag Wieers’ RPM repository has RPMs for various Red Hat-based distributions. Of course, you can also compile vnStat from the source files available from the project’s home page. I tested vnStat on an Ubuntu Edgy desktop; to install the software, I ran sudo apt-get install vnstat.

The first step in using vnStat is to initialize it and configure it to read your Internet bandwidth usage. Since I connect to my network using the eth0 port, I ran the command sudo vnstat -u -i eth0 to initialize the vnStat database. The database is stored in a file in the /var/lib/vnstat/ directory in a small binary file.

Click to enlarge

During installation vnStat sets up a cron job that refreshes the bandwidth consumption data on the eth0 port every five minutes. After letting the program run for a few minutes, type vnstat with no arguments. Like magic you’ll see something like this:

You can display your data in hourly, daily, or monthly increments using the -h, -d, and -m arguments. If you need to know more, the only documentation available is the man page and a FAQ at the project’s home page.

If you’re not satisfied with the appearance of vnStat’s command-line interface, you can install Bjorge Dijkstra’s PHP-based Web front end for vnStat, which takes the data collected by the command-line vnStat and displays it in tables and graphically in your browser. The front end requires a Web server configured with PHP.

vnStat GUI – click to enlarge

Download the tarball, extract the files into a subdirectory of your Web server’s document root directory — most likely /var/www/ or /var/www/html — and give it the right permissions so the Web server can write to it:# sudo mkdir /var/www/vnstat
# sudo tar -zxvf /home/justforkix/vnstat_php_frontend-1.2.1.tar.gz -C /var/www/vnstat/
# sudo -R chown www-data.www-data /var/www/vnstat

Launch your browser and visit the vnStat page at http://localhost/vnstat. To check out the fancy graphs, click on the “hourly” link associated with your Internet connection. The graphs are simple and straightforward, and you cannot customize them.

In just a few minutes, vnStat can help you start keeping track of your network bandwidth usage.