{"id":11681,"date":"2019-03-15T21:49:54","date_gmt":"2019-03-15T21:49:54","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11681"},"modified":"2019-03-15T21:49:54","modified_gmt":"2019-03-15T21:49:54","slug":"vnstat-php-a-web-based-interface-for-monitoring-network-bandwidth-usage","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/15\/vnstat-php-a-web-based-interface-for-monitoring-network-bandwidth-usage\/","title":{"rendered":"VnStat PHP: A Web Based Interface for Monitoring Network Bandwidth Usage"},"content":{"rendered":"<p><strong>VnStat PHP<\/strong>\u00a0a graphical interface application for most famous console mode network logger utility called \u201c<strong>vnstat<\/strong>\u201c. This\u00a0<strong>VnStat PHP<\/strong>\u00a0is a graphical frontend to\u00a0<strong>VnStat<\/strong>, to view and monitor network traffic bandwidth usage report in nicely graphical format. It display\u00a0<strong>IN<\/strong>\u00a0and\u00a0<strong>OUT<\/strong>\u00a0network traffic statistics in\u00a0<strong>hourly<\/strong>,\u00a0<strong>days<\/strong>,\u00a0<strong>months<\/strong>\u00a0or full\u00a0<strong>summary<\/strong>.<\/p>\n<p>This article shows you how to install\u00a0<strong>VnStat<\/strong>\u00a0and\u00a0<strong>VnStat PHP<\/strong>\u00a0 in Linux systems.<\/p>\n<h3>VnStat PHP Prerequisites<\/h3>\n<p>You need to install the following software packages on your system.<\/p>\n<ol>\n<li><strong>VnStat<\/strong>\u00a0: A command-line network bandwidth monitoring tool, must be installed, configured and should collect network bandwidth statistics.<\/li>\n<li><strong>Apache<\/strong>\u00a0: A Web Server to serve web pages.<\/li>\n<li><strong>PHP 5<\/strong>\u00a0: A server-side scripting language for executing php scripts on the server.<\/li>\n<li><strong>php-gd extension<\/strong>\u00a0: A GD extension for serving graphic images.<\/li>\n<\/ol>\n<h3>Step 1: Installing and Configuring VnStat Command Line Tool<\/h3>\n<p><strong>VnStat<\/strong>\u00a0is an command line network bandwidth monitoring utility which counts bandwidth (<strong>transmit<\/strong>\u00a0and\u00a0<strong>received<\/strong>) on network devices and keeps the data in its own database.<\/p>\n<p><strong>Vnstat<\/strong>\u00a0is a third party tool and can be installed via\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-enable-epel-repository-for-rhel-centos-6-5\/\" target=\"_blank\" rel=\"noopener\">enabling epel repository<\/a>\u00a0under\u00a0<strong>Red Hat<\/strong>\u00a0based systems. Once you\u2019ve enabled, you can install it using\u00a0<strong>yum command<\/strong>\u00a0as shown below.<\/p>\n<h5>On RHEL\/CentOS and Fedora<\/h5>\n<pre># yum install vnstat<\/pre>\n<h5>On Debian\/Ubuntu and Linux Mint<\/h5>\n<p><strong>Debian<\/strong>\u00a0user\u2019s simply\u00a0<strong>apt-get<\/strong>\u00a0to install<\/p>\n<pre>$ sudo apt-get install vnstat<\/pre>\n<p>As I said\u00a0<strong>Vnstat<\/strong>\u00a0maintains its own database to keep all network information. To create new database for network interface called \u201c<strong>eth0<\/strong>\u201c, issue the following command. Make sure to replace interface name as per your requirements.<\/p>\n<pre># vnstat -i eth0\r\n\r\nError: Unable to read database \"\/var\/lib\/vnstat\/eth0\".\r\nInfo: -&gt; A new database has been created.<\/pre>\n<p>If you get above error, don\u2019t worry about such error, because you are executing the command first time. So, its creates new database for\u00a0<strong>eth0<\/strong>.<\/p>\n<p>Now run following command to update all enabled databases or only specific interface with\u00a0<strong>-i<\/strong>\u00a0parameter as shown. It will generate traffic statistics of\u00a0<strong>IN<\/strong>\u00a0and\u00a0<strong>OUT<\/strong>\u00a0of a\u00a0<strong>IN<\/strong>\u00a0and\u00a0<strong>OUT<\/strong>\u00a0of a eth0 interface.<\/p>\n<pre># vnstat -u -i eth0<\/pre>\n<p>Next, add a crontab that runs every\u00a0<strong>5min<\/strong>\u00a0and update\u00a0<strong>eth0<\/strong>\u00a0database to generate traffic statistics.<\/p>\n<pre>*\/5 * * * * \/usr\/bin\/vnstat -u &gt;\/dev\/null 2&gt;&amp;1<\/pre>\n<h3>Step 2: Installing Apache, Php and Php-gd Extension<\/h3>\n<p>Install the following software packages with the help of package manager tool called \u201c<strong>yum<\/strong>\u201d for\u00a0<strong>Red Hat<\/strong>\u00a0based systems and \u201c<strong>apt-get<\/strong>\u201d for\u00a0<strong>Debian<\/strong>\u00a0based systems.<\/p>\n<h5>On RHEL\/CentOS and Fedora<\/h5>\n<pre># yum install httpd php php-gd<\/pre>\n<p>Turn on\u00a0<strong>Apache<\/strong>\u00a0at system start-up and start the service.<\/p>\n<pre># chkconfig httpd on\r\n# service httpd start<\/pre>\n<p>Run the following \u201c<strong>iptables<\/strong>\u201d command to open Apache port \u201c<strong>80<\/strong>\u201d on firewall and then restart the service.<\/p>\n<pre># iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT\r\n# service iptables restart<\/pre>\n<h5>On Debian\/Ubuntu and Linux Mint<\/h5>\n<pre>$ sudo apt-get install apache2 php5 php5-gd<\/pre>\n<pre>$ sudo \/etc\/init.d\/apache2 start<\/pre>\n<p>Open port\u00a0<strong>80<\/strong>\u00a0for Apache.<\/p>\n<pre>$ sudo ufw allow 80<\/pre>\n<h3>Step 3: Downloading VnStat PHP Frontend<\/h3>\n<p>Download latest\u00a0<strong>VnStat PHP<\/strong>\u00a0source tarball file using \u201c<a href=\"https:\/\/www.tecmint.com\/10-wget-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">wget command<\/a>\u201d as shown below or visit\u00a0<a href=\"http:\/\/www.sqweek.com\/sqweek\/index.php?p=1\" target=\"_blank\" rel=\"nofollow noopener\">THIS PAGE<\/a>\u00a0to grab latest version.<\/p>\n<pre># cd \/tmp\r\n# wget http:\/\/www.sqweek.com\/sqweek\/files\/vnstat_php_frontend-1.5.1.tar.gz<\/pre>\n<p>Extract the source tarball file, using \u201c<a href=\"https:\/\/www.tecmint.com\/18-tar-command-examples-in-linux\/\" target=\"_blank\" rel=\"noopener\">tar command<\/a>\u201d as shown given.<\/p>\n<pre># tar xvf vnstat_php_frontend-1.5.1.tar.gz<\/pre>\n<h3>Step 4: Installing VnStat PHP Frontend<\/h3>\n<p>Once extracted, you will see a directory called \u201c<strong>vnstat_php_frontend-1.5.1<\/strong>\u201c. Copy the contents of this directory to web server root location as directory\u00a0<strong>vnstat<\/strong>\u00a0as shown below.<\/p>\n<h5>On RHEL\/CentOS and Fedora<\/h5>\n<pre># cp -fr vnstat_php_frontend-1.5.1\/ \/var\/www\/html\/vnstat<\/pre>\n<p>If\u00a0<strong>SELinux<\/strong>\u00a0enabled on your system, run the \u201c<strong>restorecon<\/strong>\u201d command to restore files default\u00a0<strong>SELinux<\/strong>\u00a0security contexts.<\/p>\n<pre># restorecon -Rv \/var\/www\/html\/vnstat\/<\/pre>\n<h5>On Debian\/Ubuntu and Linux Mint<\/h5>\n<pre># cp -fr vnstat_php_frontend-1.5.1\/ \/var\/www\/vnstat<\/pre>\n<h3>Step 5: Configuring VnStat PHP Frontend<\/h3>\n<p>Configure it to match your setup. To do open the following file with\u00a0<strong>VI<\/strong>\u00a0editor and change the parameters as shown below.<\/p>\n<h5>On RHEL\/CentOS and Fedora<\/h5>\n<pre># vi \/var\/www\/html\/vnstat\/config.php<\/pre>\n<h5>On Debian\/Ubuntu and Linux Mint<\/h5>\n<pre># vi \/var\/www\/vnstat\/config.php<\/pre>\n<p>Set your default\u00a0<strong>Lagrange<\/strong>.<\/p>\n<pre>\/\/ edit these to reflect your particular situation\r\n$locale = 'en_US.UTF-8';\r\n$language = '<strong>en<\/strong>';<\/pre>\n<p>Define your network interfaces to be monitored.<\/p>\n<pre>\/\/ list of network interfaces monitored by vnStat\r\n$iface_list = array('<strong>eth0<\/strong>', '<strong>eth1<\/strong>');<\/pre>\n<p>You can set custom names for your network interfaces.<\/p>\n<pre>\/\/ optional names for interfaces\r\n\/\/ if there's no name set for an interface then the interface identifier.\r\n\/\/ will be displayed instead\r\n$iface_title['eth0'] = '<strong>Internal<\/strong>';\r\n$iface_title['eth1'] = '<strong>External<\/strong>';<\/pre>\n<p>Save and close the file.<\/p>\n<h3>Step 6: Access VnStat PHP and View Graphs<\/h3>\n<p>Open your favourite browser and navigate to any of the following link. Now you will see a fancy network graphs that shows you a summary of network bandwidth usage in\u00a0<strong>hours<\/strong>,\u00a0<strong>days<\/strong>\u00a0and\u00a0<strong>months<\/strong>.<\/p>\n<pre>http:\/\/localhost\/vnstat\/\r\nhttp:\/\/your-ip-address\/vnstat\/<\/pre>\n<h5>Sample Output<\/h5>\n<div id=\"attachment_3521\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/vnstat-php-frontend-for-monitoring-network-bandwidth\/vnstat-php\/\" rel=\"attachment wp-att-3521\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3521\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2013\/07\/VnStat-PHP.jpg\" alt=\"Install Vnstat PHP in Linux\" width=\"575\" height=\"450\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">VnStat PHP Network Summary<\/p>\n<\/div>\n<h3>Reference Link<\/h3>\n<p><a href=\"http:\/\/www.sqweek.com\/sqweek\/?p=1\" target=\"_blank\" rel=\"nofollow noopener\">VnStat PHP Homepage<\/a><\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/vnstat-php-frontend-for-monitoring-network-bandwidth\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>VnStat PHP\u00a0a graphical interface application for most famous console mode network logger utility called \u201cvnstat\u201c. This\u00a0VnStat PHP\u00a0is a graphical frontend to\u00a0VnStat, to view and monitor network traffic bandwidth usage report in nicely graphical format. It display\u00a0IN\u00a0and\u00a0OUT\u00a0network traffic statistics in\u00a0hourly,\u00a0days,\u00a0months\u00a0or full\u00a0summary. This article shows you how to install\u00a0VnStat\u00a0and\u00a0VnStat PHP\u00a0 in Linux systems. VnStat PHP Prerequisites You &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/15\/vnstat-php-a-web-based-interface-for-monitoring-network-bandwidth-usage\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;VnStat PHP: A Web Based Interface for Monitoring Network Bandwidth Usage&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11681","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11681","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11681"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11681\/revisions"}],"predecessor-version":[{"id":11682,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11681\/revisions\/11682"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}