How to Monitor Bandwidth Usage with vnStat on Linux CentOS 6.2 Server

vnStat is a open source monitoring tool that can be use to monitor the bandwidth usage of the network traffic for Linux and BSD. vnStat actually will not be sniffing any traffic and use less of the system resources. However, at least a linux kernel 2.2 series is required. Some of the vnStat features are as below :

  • quick and simple to install and get running
  • gathered statistics persists through system reboots
  • can monitor multiple interfaces at the same time
  • several output options
    • summary, hourly, daily, monthly, weekly, top 10 days
    • optional png image output (using libgd)
  • months can be configured to follow billing period
  • light, minimal resource usage
  • same low cpu usage regardless of traffic
  • can be used without root permissions
  • online color configuration editor

In this post, i will guide through the steps on how to install and configure vnStat on CentOS 6.2. These steps was tested using the Local Yum Repository from CD-ROM/DVD-ROM image and EPEL repository. Therefore it is recommended to install Local Yum Repository from CD-ROM/DVD-ROM and EPEl repository as documented in the following post.
1. Install and configure Local Yum Repository from CD-ROM/DVD-ROM image and EPEL Repository as per below posts :

See also  How to Configure Email on Android

How to Install and Configure EPEL Repository on CentOS 6.2
How to Setup Local Yum Repository from CD-ROM/DVD-ROM image on CentOS 6.2

2. Install vnStat using yum command :

[root@centos62 ~]# yum install vnstat -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.hostemo.com
 * epel: ftp.riken.jp
 * extras: mirrors.hostemo.com
 * updates: ossm.utm.my
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vnstat.i686 0:1.11-1.el6 will be installed
--> Processing Dependency: libgd.so.2 for package: vnstat-1.11-1.el6.i686
--> Running transaction check
---> Package gd.i686 0:2.0.35-10.el6 will be installed
--> Processing Dependency: libXpm.so.4 for package: gd-2.0.35-10.el6.i686
--> Running transaction check
---> Package libXpm.i686 0:3.5.8-2.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================
 Package           Arch            Version                    Repository                       Size
====================================================================================================
Installing:
 vnstat            i686            1.11-1.el6                 epel                            104 k
Installing for dependencies:
 gd                i686            2.0.35-10.el6              CentOS6.2-Repository            141 k
 libXpm            i686            3.5.8-2.el6                CentOS6.2-Repository             58 k

Transaction Summary
====================================================================================================
Install       3 Package(s)

Total download size: 304 k
Installed size: 944 k
Downloading Packages:
(1/3): vnstat-1.11-1.el6.i686.rpm                                            | 104 kB     00:00
----------------------------------------------------------------------------------------------------
Total                                                               227 kB/s | 304 kB     00:01
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing : libXpm-3.5.8-2.el6.i686                                                          1/3
  Installing : gd-2.0.35-10.el6.i686                                                            2/3
  Installing : vnstat-1.11-1.el6.i686                                                           3/3

Installed:
  vnstat.i686 0:1.11-1.el6

Dependency Installed:
  gd.i686 0:2.0.35-10.el6                         libXpm.i686 0:3.5.8-2.el6

Complete!

3. Start the vnStat service :

[root@centos62 ~]# service vnstat start
Starting vnstatd:                                          [  OK  ]

4. To ensure that vnStat is started at boot time, you can execute a chkconfig command as below :

[root@centos62 ~]# chkconfig vnstat on

5. Execute command “vnstat –iflist” to display the available network interface :

[root@centos62 ~]# vnstat --iflist
Available interfaces: lo eth0

6. Before vnStat can begin logging the bandwidth usage, it is necessary to setup the database for your network interface. Kindly replace the “eth0” with the correct interface if you running multiple interface :

[root@centos62 ~]# vnstat -u -i eth0

7. View the first vnStat data :

[root@centos62 ~]# vnstat
Database updated: Thu Mar 8 20:41:00 2012

eth0 since 03/08/12

rx: 75 KiB tx: 73 KiB total: 148 KiB

monthly
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
Mar '12 75 KiB | 73 KiB | 148 KiB | 0.00 kbit/s
------------------------+-------------+-------------+---------------
estimated -- | -- | -- |

daily
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
today 75 KiB | 73 KiB | 148 KiB | 0.02 kbit/s
------------------------+-------------+-------------+---------------
estimated -- | -- | -- |

8. View vnStat bandwidth statistic by day :

[root@centos62 ~]# vnstat -d

 eth0  /  daily

         day         rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
      03/08/12        75 KiB |      73 KiB |     148 KiB |    0.02 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated        --     |      --     |      --     |

9. View vnStat bandwidth statistic by hour :

[root@centos62 ~]# vnstat -h
 eth0                                                                     20:41
  ^                                                                       r
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
  |                                                                       rt
 -+--------------------------------------------------------------------------->
  |  21 22 23 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20

 h  rx (KiB)   tx (KiB)      h  rx (KiB)   tx (KiB)      h  rx (KiB)   tx (KiB)
21          0          0    05          0          0    13          0          0
22          0          0    06          0          0    14          0          0
23          0          0    07          0          0    15          0          0
00          0          0    08          0          0    16          0          0
01          0          0    09          0          0    17          0          0
02          0          0    10          0          0    18          0          0
03          0          0    11          0          0    19          0          0
04          0          0    12          0          0    20         75         73

10. Update the vnStat database :

[root@centos62 ~]# vnstat -u

11. View vnStat help and other available command :

[root@centos62 ~]# vnstat --help
 vnStat 1.11 by Teemu Toivola 

         -q,  --query          query database
         -h,  --hours          show hours
         -d,  --days           show days
         -m,  --months         show months
         -w,  --weeks          show weeks
         -t,  --top10          show top10
         -s,  --short          use short output
         -u,  --update         update database
         -i,  --iface          select interface (default: eth0)
         -?,  --help           short help
         -v,  --version        show version
         -tr, --traffic        calculate traffic
         -ru, --rateunit       swap configured rate unit
         -l,  --live           show transfer rate in real time

See also "--longhelp" for complete options list and "man vnstat".

How to Reset the Directory Manager Password on RHEL 7 / CentOS 7
How to Reset the Directory Manager Password on RHEL 7 / CentOS 7

It is best practice to remember passwords, but because too many passwords, sometimes we forget. We are not encouraged to write the password on any paper or share the password...

How to Find Big Files Size on Linux RHEL/CentOS
How to Find Big Files Size on Linux RHEL/CentOS

As the linux administrator, sometimes we have to identify which files are most take much space in the linux server resulting in low free space. Low disk space can also...

Why Linux users should worry about malware and what they can do about it
Why Linux users should worry about malware and what they can do about it

Don’t drop your guard just because you’re running Linux. Preventing the spread of malware and/or dealing with the consequences of infection are a fact of life when using computers. If...

How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7
How to Reset Forgotten Root Password on Linux RHEL 7 / CentOS 7

This short howto will explain the steps to reset a lost root password or to reset a forgotten root password on Linux RHEL 7 or CentOS 7. Basically, we will...

How to Update CentOS or Upgrade CentOS to the Latest Version
How to Update CentOS or Upgrade CentOS to the Latest Version

Recently, the latest version of CentOS 7.3 was released. All users of CentOS 7.0, 7.1 and 7.2 can upgrade their system to the most recent. This quick guide will explain...

How to Change your WordPress Username, Nickname and Display Name in MySQL
How to Change your WordPress Username, Nickname and Display Name in MySQL

After you create an account log in WordPress, you may want to change your WordPress username, as appropriate or due to security reason. However, you can not do this from...

How to Enable SSH Root Login on Ubuntu 16.04
How to Enable SSH Root Login on Ubuntu 16.04

As what we wrote in the previous article on how to allow SSH root on Ubuntu 14.04, after installing a fresh new copy of Ubuntu 16.04 LTS, we find that...

How to Change UUID of Linux Partition on CentOS 7
How to Change UUID of Linux Partition on CentOS 7

UUID (Universally Unique IDentifier) should be unique and it is used to identify storage devices on a linux system. If you cloned a virtual machine from vCenter, the metadata containing...

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *