jump to navigation

Bandwidth monitoring with vnStat and php-gd November 27, 2010

Posted by Tournas Dimitrios in Linux admin tools.

My previous article demonstrated how to install the php-gd graphics library on a CentOs 5 box . Lets create a web-based bandwidth monitoring tool that integrates php-gd and the linux command vnstat

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. First run “rpm -qa | grep -i vnstat ” , if no results are returned then you must install the rpm package . Epel repository provides a rpm package ready-made for Red had based distributions . This article outlines how to add Epel repo on your repository list . Run ” yum install vnstat ” to install the package .

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. 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:

Click to enlarge

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 (and php-gd installed) .

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:

#wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz
#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. For demonstrating this functionality I downloaded some “dumb huge files from this site ” . The result on my browser is like this :


No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s