vnstat is a command line bandwidth monitoring tool for Linux and UNIX operating systems.
This guide assumes that we are installing to an Ubuntu host.
vnstat can be installed directly from the main repository by running:
# apt-get install vnstat
vnstat by default will detect all interfaces on the system and begin logging their data throughput, and assume they are all 100Mbps links. Since this is rarely correct, changes can be made to the configuration file located at
Interface "bond0" MaxBandwidth 1000 MaxBWbond0 2000
These modifications are the most common. The first is changing the default interface should none be specified when running the command. The second sets the maximum bandwidth in Mbps for all the interfaces. Each interface bandwidth can be overridden as shown in the last line. The interface name must appear without a space after MaxBW and the speed again is in Mbps.
After applying the changes, restart vnstat by running:
# service vnstat restart
If any interfaces that vnstat detected are not desired, you can remove them and their database by running the following as an example for removing interface eth2:
# vnstat --delete --iface eth2 --force
vnstat PHP Frontend
There is a very useful graphical frontend for vnstat that can be used if the machine has a PHP web server.
Download the tarball from sqweek.
Extract the contents into a directory on the web server.
Configuration is done by editing
$language = 'en'; $iface_list = array('bond0', 'eth0', 'eth1'); //$iface_title['eth0'] = 'Main';
The language by default is not English and can easily be changed. The monitored interfaces can also be changed by editing the array. Interfaces can be given friendly names. If omitted or commented out, they will revert to the kernel identifier.
Databases can be migrated from host to host by copying
/var/lib/vnstat/ to the new host and changing the names of each file to correspond to the name of the new interfaces.