Graphical Bandwidth Monitor for Ubuntu
After having shifted to Ubuntu from Windows for quite a long time, I was looking for a no nonsense Bandwidth Monitor. It was during this time that I came across vnStat.
vnStat in the makers word :
vnStat is a network traffic monitor for Linux that keeps a log of daily network traffic for the selected interface(s). vnStat isn’t a packet sniffer. The traffic information is analyzed from the /proc filesystem. That way vnStat can be used even without root permissions. However, at least a 2.2 series kernel is required.
This program is open source/GPL’ed and can be installed either as root or as a single user. Better instructions are included in the README.
So I installed vnStat using
:~$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 use a wireless network and my wireless card is detected as wlan0 , I ran the following command
:~$sudo vnstat -u -i wlan0
to initialize the vnStat database. The database is stored in a file in the /var/lib/vnstat/ directory in a small binary file.
During installation vnStat sets up a cron job that refreshes the bandwidth consumption data on the wlan0(eth0 by default) port every five minutes. After letting the program run for a few minutes, type
with no arguments. You will end up see something like this:
:~$vnstat rx / tx / total / estimated eth0 [disabled]: 27.03. 213.19 MB / 1.75 GB / 1.96 GB today 186.04 MB / 2.29 GB / 2.47 GB / 8.93 GB wlan0: yesterday 1.77 GB / 1.91 GB / 3.68 GB today 735.70 MB / 1.04 GB / 1.76 GB / 6.35 GB
Note : Since i am having two interfaces aka eth0 and wlan0 hence the outcome of vnstat is like that.
In case you have only one network inetrface you would have seen something like this
:~$vnstat Database updated: Sun Dec 2 22:20:01 2007 inet (eth0) received: 735.00 GB (48.9%) transmitted: 769.38 GB (51.1%) total: 1.47 TB rx | tx | total -----------------------+------------+----------- yesterday 23.35 MB | 20.25 MB | 43.60 MB today 27.47 MB | 21.37 MB | 48.84 MB -----------------------+------------+----------- estimated 29 MB | 22 MB | 51 MB
The above data is from vnStat homepage itself.
You can display your data in hourly, daily, or monthly increments using the -h, -d, and -m arguments.
In case you want to monitor a particular interface use the following command
vnstat -i [interfaceID]
In my case i would like to monitor the wireless adapter. So i used
:~$vnstat -i wlan0
The output was as follows :
:~$ vnstat -i wlan0 Database updated: Fri Apr 3 07:50:01 2009 wlan0 received: 3.49 GB (28.8%) transmitted: 8.63 GB (71.2%) total: 12.12 GB rx | tx | total -----------------------+------------+----------- yesterday 1.77 GB | 1.91 GB | 3.68 GB today 915.66 MB | 1.24 GB | 2.13 GB -----------------------+------------+----------- estimated 2.73 GB | 3.79 GB | 6.52 GB
Now since I was not satisfied with the appearance of vnStat’s command-line interface, I started searching for somethign more graphical and came across 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.
As per vnStat PHP Frontend :
This is a PHP fronted end to vnStat, a network traffic logger. Since vnStat is console mode only I created this script to make a ‘nice’ report of the data collected by vnStat.
This script requires a working PHP setup with GD image libraries. Also vnStat must be properly installed and collecting data.
Since this required a Web Server and PHP to work i went ahead and downloaded XAMPP for Linux. Installation of XAMPP takes care of installing Apache, PHP, GD Image libraries. Just follow the instructions on the home page and you should be fine.
Next I downloaded the tarball of the vnStat PHP Frontend and extracted it to the htdocs location that was created by XAMPP aka
using the command
:~$ sudo mkdir /opt/lampp/htdocs/vnstat :~$ sudo tar -zxvf /home/[Your_user_name]/[Your_Download_Location]/vnstat_php_frontend-1.2.1.tar.gz -C /opt/lampp/htdocs/vnstat/
Now we need to make some configurations.
:~$ cd /opt/lampp/htdocs/vnstat :~$ sudo gedit config.php
In the file find this line
$iface_list = array('eth0', 'wlan0', 'sixxs');
Make sure the array reflects all your adapters that you use. For me I had to change the second one from ‘eth1′ to ‘wlan0′. Next find these line
$iface_title['eth0'] = 'Internal'; $iface_title['wlan0'] = 'Internet'; $iface_title['sixxs'] = 'SixXS IPv6';
Make sure the parameters for the $iface_title match those in the array.
Next find the following line
$data_dir = './dumps';
Change the location to a folder on your home directory with write permissions. Save the file.
Now set up a cron job which will run the following command every 5 minutes continuously.
vnstat --dumpdb -i eth0 > /path/to/data_dir/vnstat_dump_$iface
/path/to/data_dir/ = the folder on your home directory with write permission
$iface = the network adapter that you want to monitor and should match with the array list in the config.php file just you had edited just above.
The cron job is set so that you always have the latest data with you w/o loosing it and also that you can use on your own and do what ever you like.
Now open up your browser and go to
and voila you are all ready with your Web based Graphical Bandwidth Monitor.