How to install and use vnstat (Network Traffic Monitor) in Linux

vnStat is a console-based network traffic monitor for Linux and BSD 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.
In this article we will show you how to install and use vnStat (Network Traffic Monitor) on RHEL/CentOS linux distribution.

vnstat features

  • 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

Install VnStat on RHEL/CentOS 6.x/7.x Linux

To start, you will need to enable the EPEL repositories for your version of Linux. To enable the EPEL repositories in CentOS/RHEL 6.x enter following command:

To enable the EPEL repositories in CentOS/RHEL 7.x enter following command:

Next, you can install VnStat as normal through yum.

Once installed, the default configuration will work for most people. The default will run on the eth0 interface. If you need to change the interfaces, you will need to edit two files. It’s self explanatory. Change the occurrences of eth0 to eth1 (or your choice of interface).

Next, we need to create the database where the data will be collected and stored. The command may generate an error. If it does, that’s fine. It is because the new file is created with ownership of the logged in user. We will fix this by running a chown on the file before starting the service.

That’s it. You’re ready to start the service and start collecting data.

How to use VnStat

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.

You can see hourly, daily, weekly or montly statistics.

To get daily stats enter:

vnstat

To get weekly stats enter:

To get monthly stats enter:

To get hourly stats enter:

To see traffic in real time enter:

vnstat_realtime_traffic

 

 

 

Check man pages for more info on usage.

Want me to do this for you? Drop me a line: itgalaxyzzz {at} gmail [dot] com