How to Monitor Network Bandwidth Usage - VnStat PHP
To Monitor Network Bandwidth Usage - VnStat PHP
A graphical interface application for most famous console mode network logger utility called “ vnstat“ . It is a graphical frontend to VnStat used to view and monitor network traffic bandwidth. VnStat PHP installation is explained in this article.
VnStat PHP Requirements
Apache 2 : A Web Server to serve web pages.
VnStat : A command-line network bandwidth monitoring tool, must be installed, configured and should collect network bandwidth statistics.
php-gd extension : A GD extension for serving graphic images.
PHP 7 : A server-side scripting language for executing php scripts on the server.
To Install and Configure the VnStat Command Line Tool
Run the following command to install and configure the VnStat command Line tool, apache2 and php.
root@linuxhelp:~# apt-get install apache2 php php-xml libapache2-mod-php vnstat
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
apache2-doc apache2-suexec-pristine | apache2-suexec-custom vnstati
The following NEW packages will be installed:
apache2 libapache2-mod-php php php-xml vnstat
.
.
.
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
To Download the VnStat PHP Frontend
First goto /tmp/ directory and use " wget command" to download the latest VnStat PHP source tarball file.
root@linuxhelp:~# cd /tmp/
root@linuxhelp:/tmp# wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz
--2016-06-09 10:31:39-- http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz
Resolving www.sqweek.com (www.sqweek.com)... 164.138.27.72
Connecting to www.sqweek.com (www.sqweek.com)|164.138.27.72|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 57460 (56K) [application/x-gzip]
Saving to: ‘ vnstat_php_frontend-1.5.1.tar.gz’
vnstat_php_frontend 100%[===================> ] 56.11K 164KB/s in 0.3s
2016-06-09 10:31:40 (164 KB/s) - ‘ vnstat_php_frontend-1.5.1.tar.gz’ saved [57460/57460]
To Extract VnStat PHP tar file
Use “ tar” command to extract the tar file.
root@linuxhelp:/tmp# tar -zxvf vnstat_php_frontend-1.5.1.tar.gz
vnstat_php_frontend-1.5.1/
vnstat_php_frontend-1.5.1/VeraBd.ttf
vnstat_php_frontend-1.5.1/README
.
.
.
vnstat_php_frontend-1.5.1/vnstat.php
vnstat_php_frontend-1.5.1/graph_svg.php
vnstat_php_frontend-1.5.1/localize.php
vnstat_php_frontend-1.5.1/vera_copyright.txt
Copy the extracted directory to vnstat directory located in “ /var/www/html” .
root@linuxhelp:/tmp# cp -a vnstat_php_frontend-1.5.1 /var/www/html/vnstat
To Configure VnStat PHP Frontend
Open the config.php file and change the parameters as shown below.
root@linuxhelp:/tmp# nano /var/www/html/vnstat/config.php
Set the default Language as required.
// edit these to reflect your particular situation $locale = ' en_US.UTF-8' $language = ' en'
Define the network interfaces to be monitored.
// list of network interfaces monitored by vnStat $iface_list = array(' ens33' )
Now set custom names for the 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[' ens33' ] = ' Internal' //$iface_title[' eth1' ] = ' External'
Save the file and restart apache service.
root@linuxhelp:/tmp# service apache2 restart
To Access the VnStat PHP and View Graphs
Open the browser and navigate to http://localhost/vnstat/ or http://< ip-address> /vnstat/. It shows the fancy network graphs with the summary of network bandwidth usage in hours, days and months.
Hours vise graph
Date vise graph
Month vise graph
2. Apache : A Web Server to serve web pages.
3. PHP 5: A server-side scripting language for executing php scripts on the server.
4. php-gd extension: A GD extension for serving graphic images.