Server Administration & Management

How to configure vnStat for monitoring bandwidth usage

VMSTAT is a tool for those people, having dedicated server hosted somewhere remote at IDC/ISP.

vnStat is a console-based network traffic monitor for Linux that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that vnStat won’t actually be sniffing any traffic and also ensures light use of system resources. However, in Linux at least a 2.2 series kernel is required.

* It keeps a log of daily and monthly network traffic for the selected network interface(s).
* It collects all data from /proc file system it means normal user can monitor traffic (no need to run vnstat as a root user)
* Easy to setup & configure
* Ease of use

1. Install vnstat using yum

# yum install vnstat

2. Setup database: Before vnStat can begin logging bandwidth usage you need to tell it to setup the database for your network interface.
Replace eth0 with the correct interface

# vnstat -u -i eth0


-u :forces a database update for interface or creates the database if it doesn’t exist
-i eth0 : use to specify interface

3. Setup correct interface in config file: By default the vnStat cron job will attempt to collect statistics for the eth0 interface.
If your network interface is different from that one you will have to modifiy the /etc/sysconfig/vnstat file:

# vi /etc/sysconfig/vnstat


4. Setup bash alias: Logout of root now and back to your regular user account. If you intend to use vnstat over the command line and
your network interface is not eth0 you should setup a bash alias for ease of use in your .bashrc file:

alias vnstat=”vnstat -i eth3″

5. Statistics by day

# vnstat -d

6. Statistics by Hour

# vmstat -h

7. Statistics By month

# vnstat -m

8. Live monitoring of the network interface

# vnstat -l

9. Display all time top10 traffic days

# vnstat -t

October 15, 2011 Posted by | Tips & Tricks, Unix/Linux | , , , , | Leave a comment