How to Setup vnStat (Network Monitoring tool) on CentOS / RHEL / Fedora

Channel: Linux
Abstract: # rpm -Uvh http# rpm -Uvh http

vnStat is a utility which counts bandwidth ( transmit and received ) on network interface and stored in own database. This article will help you for installing vnStat on your server and create web-based graph using PHP application.

Install vnStat Command Line Tool on Linux

First we need to install vnStat command line tool to get network statics and store it. Use below steps to install and configure it.

Step 1: Install rpmforge Repository
CentOS/RHEL 6, 32 Bit (i686):
# rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm

CentOS/RHEL 6, 64 Bit (x86_64):
# rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

CentOS/RHEL 5, 32 Bit (i386):
# rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpm

CentOS/RHEL 5, 64 Bit (x86_64):
# rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.x86_64.rpm
Step 2: Install vnStat package using Yum

Use yum command line utility to install vnstat package on your system.

# yum install vnstat
Step 3: Initialize database

vnStat keep all information in a database, Use below command to create database for network interface. This article is using interface eth0. Change interface name as per your requirements.

# vnstat -u -i eth0
Step 4: Schedule Cron

vnStat uses cron job to update database. By default it’s configured to execute on 5 minutes interval. Edit /etc/cron.d/vnstat file and make changes as below

MAILTO=root
*/5 * * * * root /usr/sbin/vnstat.cron
Step 5: Configure Interface in Configuration

By default vnStat are configured to collect information from eth0, Edit /etc/sysconfig/vnstat file and update option as below.

VNSTAT_OPTIONS="-i eth0"
Step 6: Show Statics using vnStat Command Line

Using vnstat command line utility you can view statistics on bandwidth on per day, per month and per hour basis. It also provides option to show statistics in real-time.

  • Show Statistics for a day
# vnstat -d 

 eth0  /  daily

         day         rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
      05/07/13    213.12 MiB |  837.71 MiB |    1.03 GiB |  120.06 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated       256 MiB |    0.98 GiB |    1.23 GiB |

  • Show Statistics for a Month
# vnstat -m
  • Show Statistics for a Hour
# vnstat -h
  • Show Statistics in Real Time
# vnstat -l
Configure vnStat PHP Web Based Interface.

vnStat also provides php based web interface to show graphical statistics. In order to set up vnStat web interface, it required to have Apache, php and php-gd packages on your system.

If you do not have Apache, PHP install it using below article elese skip this.

Install Apache, PHP, MySQL on CentOS System

Step 1: Download vnStat Source Archive

Download vnStat php code using below given url.

# wget http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz
Step 2: Extract Archive

Extract downloaded archive in web accessible directory, eg: /var/www/html/vnstat

# tar xzf vnstat_php_frontend-1.5.1.tar.gz
# mv vnstat_php_frontend-1.5.1 /var/www/html/vnstat
Step 3: Edit Configuration File

Edit the config.php file and set the following parameters as per your setup.

$language = 'en';
$iface_list = array('eth0', 'sixxs');
$iface_title['eth0'] = 'Public Interface';
$vnstat_bin = '/usr/bin/vnstat';
Step 4: Access vnStat in Web browser

Access vnStat php code directory in web browser using domain or ip address. eg:

http://192.168.1.90/vnstat/
or
http://web.tecadmin.net/vnstat/

Congratulation’s! you have successfully configured vnStat. Read our next article to Install and Configure AWStats and Install Munin Network Monitoring Tool on your Linux system.

Ref From: tecadmin

Related articles