VnStat PHP frontend – A Web Based Interface for Monitoring Network Bandwidth

ADVERTISEMENT

VnStat PHP frontend is a graphical web interface for network utility called VnStat. VnStat PHP provides a simple graphical format where we can monitor IN and OUT traffic of network interfaces including statistics history (hourly, days, months or full summary).

This guide helps you to install VnStat PHP frontend on Linux systems.

ADVERTISEMENT
Article will continue after the ad

System Requirements:

  • Linux operating system (CentOS 6 / CentOS 7 / RHEL 6 / RHEL 7 / Ubuntu 16.04 / Ubuntu 14.04 and Debian 8)
  • Working VnStat setup
  • Web Server (Apache) with PHP support
  • PHP-GD extension for PNG graphs.

Installing and Configuring VnStat:

VnStat is a command line utility to monitor network bandwidth of interfaces and keeps the historical statistics on its database.

On CentOS / RHEL:

VnStat is not available in the main repository, so you need to enable EPEL repository for Redhat based derivatives.

# yum -y install vnstat

Once you have installed the VnStat, start it using the following command. (Ignore if it is already running).

# service vnstat start

Start VnStat on system boot using the following command.

# chkconfig vnstat on

On Debian / Ubuntu:

$ sudo apt-get install vnstat

Please wait at least ten minutes, and then run the following command. You should get similar output like below; this ensures that VnStat is working.

# vnstat

Database updated: Sun Apr 17 17:03:53 2016
   eth0 since 04/10/16
          rx:  1.12 GiB      tx:  110.13 MiB      total:  1.22 GiB
   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       Apr '16      1.12 GiB |  110.13 MiB |    1.22 GiB |    7.11 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated      2.00 GiB |     197 MiB |    2.19 GiB |
   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     yesterday     19.94 MiB |    6.73 MiB |   26.66 MiB |    2.53 kbit/s
         today      5.92 MiB |    5.26 MiB |   11.18 MiB |    1.49 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated         7 MiB |       7 MiB |      14 MiB |

Installing Apache, PHP, and php-gd:

Install the packages using “yum” on CentOS and “apt-get” on Debian,  start the Apache server after the installation.

On CentOS / RHEL:

# yum -y install httpd php php-gd wget
# chkconfig httpd on
# service httpd start

Configure the firewall to allow apache traffic (CentOS / RHEL).

### FirewallD ###

# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --reload

### IPTables ###

# iptables -A INPUT -m tcp -p tcp --dport 80 -j ACCEPT
# service iptables restart

On Ubuntu / Debian:

### Ubuntu 15.10 / 14.04 and older/ Debian ###

$ sudo apt-get install apache2 php5 php5-gd wget
$ sudo service apache2 restart

### Adding PHP 5.6 PPA for Ubuntu 16.04 ###

$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt-get update
$ sudo apt-get install apache2 php5.6 php5.6-gd wget libapache2-mod-php5.6
$ sudo service apache2 restart

Download and Install VnStat PHP frontend:

Use the wget command to download the latest VnStat PHP frontend from the official website.

# cd /tmp
# wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz

Extract the downloaded package using “tar” command.

# tar -zxvf vnstat_php_frontend-1.5.1.tar.gz

Once the extraction is completed, move the directories to web server root directory.

On CentOS / RHEL:

# cp -a vnstat_php_frontend-1.5.1 /var/www/html/vnstat
# restorecon -Rv /var/www/html/vnstat/

On Ubuntu / Debian:

### Debain / Ubuntu 14.04 and later (Apache 2.4 and later) ###

$ sudo cp -a vnstat_php_frontend-1.5.1  /var/www/html/vnstat

### Ubuntu 13.10 and below (i.e older Apache 2.x) ###

$ sudo cp -a vnstat_php_frontend-1.5.1  /var/www/vnstat

Configuring VnStat PHP frontend:

Open the configuration file and modify the parameters shown below.

### CentOS / RHEL ###

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

### Debain / Ubuntu 14.04 and later (Apache 2.4 and later) ###

$ sudo nano /var/www/html/vnstat/config.php

### Ubuntu 13.10 and below (i.e older Apache 2.x) ###

$ sudo nano /var/www/vnstat/config.php

Set the default language.

// edit these to reflect your particular situation
//
$locale = 'en_US.UTF-8';
$language = 'en';

Set which interface to be monitored.

// list of network interfaces monitored by vnStat
$iface_list = array('eth0', 'eth1');

You can name your network interfaces.

// optional names for interfaces
// if there's no name set for an interface then the interface identifier
// will be displayed instead
//
$iface_title['eth1'] = 'Internal';
$iface_title['eth0'] = 'External';

Accessing VnStat PHP frontend:

Open up your browser and navigate it to any one of the following links. You would get an output like below; it shows you the usage summary (in hours, days and months) of your network interface.

http://localhost/vnstat
http://your-ip-address/vnstat
VnStat PHP frontend - Web Based Interface for Monitoring Network
VnStat PHP frontend – Web Based Interface for Monitoring Network

Note: If you don’t get any data in the graph, consider disabling SELinux on CentOS 7 / CentOS 6.

Reference:

Official Home Page

ADVERTISEMENT

POSTS YOU MAY LIKE -:)

Share This Post

Shares