VnStat Dashboard – A Web Based Interface for Monitoring Network Bandwidth

VnStat Dashboard is a graphical web interface for VnStat, a network utility. VnStat dashboard provides a simple graphical chart where we can monitor the traffic of network interfaces. Dashboard also includes statistics history (hourly, days, months or full summary).

This post focuses on installing VnStat Dashboard on Linux systems.

Features:

  • Hourly statistics using Google Charts.
  • Daily and Monthly statistical overview.
  • Top 10 day statistics.
  • Automatic population of network interfaces.

System Requirements:

  • Linux distribution of your choice (CentOS 7 / CentOS 6 /  RHEL 7 / RHEL 6 / Debian 8 and Ubuntu 16.04 / Ubuntu 14.04 )
  • Working VnStat setup
  • Apache Web server
  • PHP and GD extension for PNG graphs.

Installing and Configuring VnStat:

VnStat is a command line tool to monitor the bandwidth of network interfaces and keeps a log of hourly, daily and monthly network traffic statistics on its database.

On CentOS / RHEL:

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

### For RHEL 7 ###

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

### For RHEL 6 ###

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

### For CentOS 7 / 6 ###

yum -y install epel-release

Install VnStat using the following command.

# yum -y install vnstat

Once the installation is complete, start VnStat using the following command. (Ignore if it is already running).

# service vnstat start

Set VnStat to autostart on system boot using the following command.

# chkconfig vnstat on

On Debian / Ubuntu:

$ sudo apt-get -y install vnstat

Please wait for some time, and then run the “vnstat” command. You should get similar output like below; this ensures that VnStat is working.

# vnstat

Database updated: Thu Nov 17 09:39:59 2016

   eth0 since 11/15/2016

          rx:  71.37 MiB      tx:  10.38 MiB      total:  81.75 MiB

   monthly
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       Nov '16     71.37 MiB |   10.38 MiB |   81.75 MiB |    0.47 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated       129 MiB |      18 MiB |     147 MiB |

   daily
                     rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     yesterday     22.61 MiB |    6.71 MiB |   29.33 MiB |    2.78 kbit/s
         today     16.31 MiB |    1.91 MiB |   18.22 MiB |    4.29 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        39 MiB |       2 MiB |      41 MiB |

Installing Apache, PHP, and php-gd:

Install the apache and PHP extensions using “yum” on CentOS and “apt-get” on Debian/Ubuntu.

On CentOS / RHEL:

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

Configure the firewall to allow external machines to access the dashboard (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 -y install apache2 php5 php5-gd wget unzip
$ 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 -y install apache2 php5.6 php5.6-gd wget libapache2-mod-php5.6
$ sudo service apache2 restart

Download and Install VnStat Dashboard:

Download the latest version of VnStat Dashboard from the official GitHub.

# cd /tmp
# wget https://github.com/alexandermarston/vnstat-dashboard/archive/master.zip

Extract the downloaded package using “unzip” command.

# unzip master.zip

Once the extraction is completed, plesae the files to web server (apache) root directory.

On CentOS / RHEL:

# cp -a /tmp/vnstat-dashboard-master/ /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 /tmp/vnstat-dashboard-master/  /var/www/html/vnstat

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

$ sudo cp -a /tmp/vnstat-dashboard-master/  /var/www/vnstat

Configuring VnStat PHP frontend:

Open up the configuration file and modify the parameters shown like 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

Update the path of vnstat executable.

// Path of vnstat
$vnstat_bin_dir = '/usr/bin/vnstat';

By default, VnStat Dashboard will display the statistics of all the interfaces. Set to true in case if you want to show the statistics of defined interfaces.

In our case, the dashboard will show statistics of “ens4 and eth1” only.

// Set to true to set your own interfaces
$use_predefined_interfaces = true;

if ($use_predefined_interfaces == true) {
    $interface_list = array("ens4", "eth1");

You can also name your network interfaces.

$interface_name['ens4'] = "Internal";
$interface_name['eth1'] = "External";

Accessing VnStat PHP frontend:

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

http://localhost/vnstat
http://your-ip-address/vnstat
VnStat Dashboard – Overview

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

Reference:

Official Home Page

centos 7debian 8fedora 24monitoring-toolsubuntu 16.04vnstat
Comments (0)
Add Comment