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.rpmCentOS/RHEL 6, 64 Bit (x86_64): # rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpmCentOS/RHEL 5, 32 Bit (i386): # rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el5.rf.i386.rpmCentOS/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
$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/
8 Comments
Thanks for the article, nicely done..
Hi Folks ,
Thank you for amazing pretty tool article.
i have a question.
i installed my centos 6 x64 cPanel WHM server but . Getting Internal Server Error
But everythings looks normal.
What can i do ?
Thanks in advance.
Regards.
Berk
Nice, a simple easy to use network monitoring tool 🙂
Excellent, what a weblog it is! This website gives helpful data to
us, keep it up.
Hello, I enjoy reading through your article. I like to write a little
comment to support you.
Excellent, thank you very much from Chile 🙂
It is very helpful topic to me.Nice article.
thanks
Thanks a lot Admin, for sharing this with all of us you actually know what you are talking about!