How to Install vnStat and vnStati to Monitor Network Traffic in RHEL/CentOS 7

VnStat is a console based network traffic monitoring tool design for Linux and BSD. It will keep a log of the network traffic for a selected network interface/s. To generate the logs, vnStat uses the information provided by the kernel. In other words it will not sniff the network traffic and will ensue the lite usage of the system resource. To use this software under Linux you will need at least version 2.2 of the kernel series.

Read Also: VnStat PHP: A Web Based Interface for Monitoring Network Traffic Usage

The latest version of vnStat 1.13 has been released on January 18th, 2015 and includes several following features and fixes.

Features

  1. Statistics remain available even after system reboots
  2. Monitor multiple network interfaces at the same time
  3. Multiple output options
  4. Sort the data by hour, day, month, week or get the top 10 days
  5. Generate png graphic of the output
  6. Configure “Months” to follow up with different billing cycles you may have
  7. Very light – consumes really small portion of your system resources
  8. Low CPU usage no matter how much traffic you generate
  9. You don’t have to be root to use it
  10. Select units dynamically (KB, MB etc)
  11. vnStati provides some new options like:
    1. -nl / –nolegend (hides the rx/tx legend)
    2. –altdate – use alternative date/time text location
    3. –headertext – to customize the text in the image header.
  12. You can add legend to generated output image
  13. Customizable options for content positioning and image background color to vnStat.cgi.
  14. The interface bandwidth will be automatically detected.
  15. Use JSON for output

In this article, we will show you how to install vnStat and vnStati tool under RHEL/CentOS 7 systems to monitor real time network traffic.

Installing vnStat and vnStati Network Monitoring Tools

1. To install vnStat in RHEL/CentOS 7 you will need to download the latest version (1.13) using following link:

  1. http://humdi.net/vnstat/

Alternatively, you can also use following wget command to download the latest source tarball as shown below.

# wget http://humdi.net/vnstat/vnstat-1.13.tar.gz
Download Vnstat

Download Vnstat

2. Once you have downloaded the file, extract the archive using your terminal and then navigate to the location where you have extracted the archive and compile it using following commands.

# tar -xvf vnstat-1.13.tar.gz
# cd vnstat-1.13/
# make
Compile Vnstat

Compile Vnstat

Once the above compilation completed successfully, run:

# make install
Install Vnstat

Install Vnstat

3. Once the install has finished you will need to create a new database for the network interface that you will be monitoring. Before you do so, make sure that the following directory exist:

/var/lib/vnstat

If that directory does not exist the database creation mail fail and you will end up getting following error

Error: Unable to open database directory "/var/lib/vnstat": No such file or directory
The vnStat daemon should have created this directory when started.
Check that it is is configured and running. See also "man vnstatd".
Vnstat Error: /var/lib/vnstat

Vnstat Error: /var/lib/vnstat

If it is missing you can create it by running following command.

# mkdir /var/lib/vnstat

4. To create a new database for your network interface run:

# vnstat --create -i eth0

Creating database for interface "eth0"...
Info: -> A new database has been created.
Vnstat Database Created

Vnstat Database Created

In my case the network interface is “eth0”, but this may vary. You can run ifconfig -a to check the available interfaces for your machine.

5. If you wish to customize your vnStat configuration you can open its configuration file located at:

/etc/vnstat.conf

The options in there are self explanatory so I won’t be stopping on each one of them. You can still review them if you wish to customize your installation.

6. You would need to allow some time for the stats to be updated in the database. Once you have enough information written in the database you can see the network stats by simply running:

# vnstat
Monitor Network Traffic of Interface

Monitor Network Traffic of Interface

7. Yon can also check the hourly stats by using the -h option:

# vnstat -h
Monitor Hourly Network Traffic

Monitor Hourly Network Traffic

8. For daily stats, you will need to use the -d option:

# vnstat -d 
Monitor Daily Network Traffic

Monitor Daily Network Traffic

9. For more available options you can use the --help:

# vnstat --help
Vnstat Monitoring Options

Vnstat Monitoring Options

10. To make the stats easier to read you can use the vnStati tool to generate .png images for vnStat.

VnStati is automatically installed along vnStat so no further installation actions would be required. To generate a summary image for the network usage of your network interface, you can run:

# vnstati -s -i eth0 -o ~/network-log.png
Generate Network Monitoring Report

Generate Network Monitoring Report

# vnstati -h -i eth0 -o ~/network-log.png
Hourly Network Report

Hourly Network Report

In my cases vnStat was just recently installed, but those will get populated over time. For more available options and different stats you can use the –help option:

The information that both vnStat and vnStati provide can greatly help your network monitoring, analysis and troubleshooting in time. You may find more information about the available options of vnStat in the man page of the tool.

If you have an additional suggestion or question about vnStat and vnStati please do not hesitate to submit your comment in the comment section below.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Marin Todorov

I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

Got something to say? Join the discussion.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.