Installing VnStat in CentOS7 – A Web Interface for Monitoring Bandwidth

Installing VnStat in CentOS 7

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.

Prerequisites

  • CentOS 7.3 (Operating system used here)
  • root privileges.
  • Working VnStat setup
  • Web Server (Apache) with PHP support
  • PHP-GD extension for PNG graphs.

Installing and Configuring VnStat:

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

Install EPEL rpm by using the following command.

[root@webhostingchennai /]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

You will get output like

Retrieving http://mirror.pnl.gov/epel/7/x86_64/e/epel-release-latest-7.noarch.rpm

warning: /var/tmp/rpm-tmp.iPpiIE: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
Preparing...                        ################################# [100%]
Updating / installing...
1:epel-release-latest-7.noarch.rpm  ################################# [100%]

List the installed repo’s:

You can find the EPEL repo in the list

[root@webhostingchennai /]# yum repolist

List the EPEL packages:

[root@webhostingchennai /]# yum --disablerepo=* --enablerepo=epel list

Install the packages

[root@webhostingchennai /]# yum install zmap

Installing VnStat:

[root@webhostingchennai /]# yum -y install vnstat

Once you have installed the VnStat, start the service by using the below command.

[root@webhostingchennai /]# systemctl start vnstat.service

Start VnStat on system boot

[root@webhostingchennai /]# chkconfig vnstat on

Wait for some time, and then run the following command. You should get similar output like below; this ensures that VnStat is working.

[root@webhostingchennai /]# vnstat
Database updated: Mon Feb 19 12:26:10 2018
   eth0 since 02/19/2018
          rx:  339 KiB      tx:  9 KiB      total:  348 KiB
   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       Feb '18      339  KiB |  9 KiB      |    348  KiB |    7.11 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated      --   GiB |     --  MiB |    --   GiB |
   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
         today      339  KiB |    9    KiB |   348   KiB |    1.49 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        -- MiB |      -- MiB |     --  MiB |

Installing Apache, PHP, and php-gd

Let install php, Apache and php extensions

[root@webhostingchennai /]# yum -y install httpd php php-gd wget
[root@webhostingchennai /]# chkconfig httpd on
[root@webhostingchennai /]# service httpd start

Configuring the firewall to allow apache traffic

Enable and start firewall

[root@webhostingchennai /]# systemctl enable firewalld
[root@webhostingchennai /]# systemctl start firewalld
[root@webhostingchennai /]# firewall-cmd --permanent --zone=public --add-service=http
[root@webhostingchennai /]# firewall-cmd --reload

Downloading and Install VnStat PHP frontend

Now, let download the latest VnStat PHP frontend from the official website

[root@webhostingchennai /]# cd /tmp
[root@webhostingchennai tmp]# wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz
[root@webhostingchennai tmp]# tar -zxvf vnstat_php_frontend-1.5.1.tar.gz

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

[root@webhostingchennai tmp]# cp -a vnstat_php_frontend-1.5.1 /var/www/html/vnstat
[root@webhostingchennai tmp]# restorecon -Rv /var/www/html/vnstat/

Configuring VnStat PHP frontend

Open the configuration file config.php and modify as below

[root@webhostingchennai tmp]# nano /var/www/html/vnstat/config.php
// edit these to reflect your particular situation
//
$locale = 'en_US.UTF-8';
$language = 'en';

Set which interfaces are to be monitored.

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

You can also name your network interfaces as you wish.

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

Accessing VnStat PHP frontend

Open up your browser and access using the below link. You would get an output like below; it shows you the usage summary (in hours, days and months) of your network interface.

http://your-ip-address/vnstat

installing vnstat

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

You may also like...

Leave a Reply

Your email address will not be published.