vnStat

The graphical front end is what makes VnStat different other monitoring tools available today. It is used to view and monitor bandwidth usage in network traffic. It uses a web based interface to establish connection and represent those findings in a nice graphical interface, which is developed using PHP.

It is helpful for administrative activities like identifying fault in network interface, detecting the root cause of traffic related issues, identifying traffic overload etc. it also helps the end user to monitor the excessive traffic flow in ISP end. It is also useful to avoid abusive bandwidth consumption. There are added features of VnStat like summarizing output on hourly, daily, monthly, weekly, basis, monitoring can be done for a particular set of defined connected interfaces and the generated output can be logged in the database for further analysis. All these features can be accessed without root privileges.

Coming to the installation part, there are different prerequisites to be taken before the installation begins. Initially all the dependencies for VnStat and PHP have to be installed using the YUM utility.  

>> yum install wget epel-release php httpd php-gd

To install vnStat just execute the following command

>> yum install vnstat

To view all the available interfaces on your system that vnStat can monitor, use the following command:

>> vnstat –iflist

Available interfaces: lo eth0 eth1

Now add the eth0 and eth1 interfaces for monitoring traffic, as follows:

>> vnstat -u -i eth0

Error: Unable to read database “/var/lib/vnstat/eth0”

Info: -> A new database has been created

For the first time, it will display the above error. Ignore this as sufficient data is not available for display.
Similarly, add the second interface, i.e., eth1, as follows:

>> vnstat -u -i eth1

Error: Unable to read database “/var/lib/vnstat/eth1”.

Info: -> A new database has been created.

Method for updating the database
The database can be updated by either using cron or service.
Cron: To use cron, just remove the comment from /etc/cron.d/vnstat, after which the entry should be as shown below:

>> vi /etc/cron.d/vnstat

MAILTO=root

*/5 * * * * vnstat /usr/sbin/vnstat.cron

:wq save and quit
Service: The second method uses vnStatd a program that collects all the information and is run as the daemon. You can start it by executing the below command:

>> /etc/init.d/vnstat start

Enable service at boot time

>>  chkconfig –level 345 vnstat on

To start traffic monitoring for selected interfaces, start vnstat service.

>> cd /usr/local/src

Download the latest vnStat PHP frontend.

Extract the downloaded archive in a Web-accessible directory, e.g. /var/www/html/

>> tar xzf vnstat_php_frontend-1.5.1.tar.gz

>> mv vnstat_php_frontend-1.5.1 /var/www/html/vnstat

Edit the config.php file and set the following parameters as per your set-up:

>> vi /var/www/html/vnstat/config.php

$language = en;

$iface_list = array(eth0, eth1);

$iface_title[eth0] = Public Interface;

$iface_title[eth1] = Local interface;

If you are using SELinux, restore the file(s) default SELinux security contexts by using the restorecon command:

>> restorecon -Rv /var/www/html/vnstat/

Make sure that the correct local time zone is set in php.ini. Edit php.ini and set date.timezone =Asia/Kolkata

>> vi /etc/php.ini

date.timezone =Asia/Kolkata

Now enable web service at boot

>> chkconfig –level 345 httpd on

Start the Web service httpd as follows:

>> service httpd start

You can access vnStat with the PHP frontend by pointing your browser to http://ipaddress/vnstat

 

Allow port 80 on the server from outside, add rule in iptables by executing below command:

>> /sbin/iptables -A INPUT -m state –state NEW -p tcp –dport 80 -j ACCEPT

>> /etc/init.d/iptables save

>> /etc/init.d/iptables restart

To secure the vnStat PHP frontend with user authentication, add an entry in httpd.conf at the end as shown below:

<Directory /var/www/html/vnstat>

AuthUserFile /var/www/vnstat-htpasswd

AuthName “vnStat user”

AuthType Basic

require valid-user

</Directory>

After making changes in the httpd.conf file, restart the httpd service:

>> service httpd restart

Create file /var/www/vnstat-htpasswd

>> touch /var/www/vnstat-htpasswd

>> htpasswd -cm /var/www/vnstat-htpasswd vnadmin

This will add the user, with Force SHA encryption of the password.
Now point your browser to http://ipaddress/vnstat/. It will ask for the user name and password. After entering both, you will be able to see the VnStat PHP frontend main page. You can get details like the summary, hourly, daily and monthly graphical reports of bandwidth usage for configured interfaces.

Written by admin

Leave a Reply

Your email address will not be published. Required fields are marked *