Install vnStat network traffic monitor on Rocky Linux

This guide is going to take you through on how to Install vnStat network traffic monitor on Rocky Linux. vnStat is a network tool for the Linux operating system that monitors network traffic using a command line interface, or console. vnStat keeps a track of network traffic for the selected interfaces on an hourly, daily, and monthly basis.

How to Install vnStat network traffic monitor on Rocky Linux

  • Update yum database with dnf using the following command.
sudo dnf makecache --refresh
  • Next Install vnStat network traffic monitor on Rocky Linux.
sudo dnf -y install vnstat

Sample output

Last metadata expiration check: 0:00:01 ago on Thu 28 Apr 2022 11:34:25 PM EAT.
Dependencies resolved.
================================================================
 Package       Architecture  Version          Repository   Size
================================================================
Installing:
 vnstat        x86_64        2.6-2.el8        epel        154 k

Transaction Summary
================================================================
Install  1 Package

Total download size: 154 k
Installed size: 528 k
Downloading Packages:
vnstat-2.6-2.el8.x86_64.rpm      18 kB/s | 154 kB     00:08    
----------------------------------------------------------------
Total                            14 kB/s | 154 kB     00:11     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                        1/1 
  Running scriptlet: vnstat-2.6-2.el8.x86_64                1/1 
  Installing       : vnstat-2.6-2.el8.x86_64                1/1 
  Running scriptlet: vnstat-2.6-2.el8.x86_64                1/1 
  Verifying        : vnstat-2.6-2.el8.x86_64                1/1 

Installed:
  vnstat-2.6-2.el8.x86_64                                       

Complete!

Configure vnStat on Rocky Linux

  • Check your interface name by running the command below.
ip l show

Sample output

1: lo:  mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens160:  mtu 1500 qdisc mq state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:8a:47:48 brd ff:ff:ff:ff:ff:ff
  • Provide the name of the interface you wish to monitor in the vnstat config file. To open the file, type the command below.
sudo nano /etc/vnstat.conf
  • Type in the name of your interface. Replace ‘ens160’ with the name of your interface, save, and close the file.
Interface "ens160"
  • Restart vnStat for changes to take effect.
sudo systemctl restart vnstat
  • vnStat should be running, check status.
sudo systemctl status vnstat.service

Sample output

● vnstat.service - vnStat network traffic monitor
   Loaded: loaded (/usr/lib/systemd/system/vnstat.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-04-28 23:47:09 EAT; 12s ago
     Docs: man:vnstatd(8)
           man:vnstat(1)
           man:vnstat.conf(5)
 Main PID: 5272 (vnstatd)
    Tasks: 1 (limit: 23385)
   Memory: 1012.0K
   CGroup: /system.slice/vnstat.service
           └─5272 /usr/sbin/vnstatd -n

Apr 28 23:47:09 localhost.localdomain systemd[1]: Started vnStat network traffic monitor.
Apr 28 23:47:09 localhost.localdomain vnstatd[5272]: No interfaces found in database, adding available interfaces...
Apr 28 23:47:09 localhost.localdomain vnstatd[5272]: Interface "ens160" added with 10000 Mbit bandwidth limit.
Apr 28 23:47:09 localhost.localdomain vnstatd[5272]: Interface "virbr0" added with 1000 Mbit bandwidth limit.
Apr 28 23:47:09 localhost.localdomain vnstatd[5272]: Interface "virbr0-nic" added with 1000 Mbit bandwidth limit.
Apr 28 23:47:09 localhost.localdomain vnstatd[5272]: -> 3 new interfaces found.
Apr 28 23:47:09 localhost.localdomain vnstatd[5272]: Limits can be modified using the configuration file. See "man vnstat.conf".
Apr 28 23:47:09 localhost.localdomain vnstatd[5272]: Unwanted interfaces can be removed from monitoring with "vnstat --remove".
Apr 28 23:47:09 localhost.localdomain vnstatd[5272]: Info: vnStat daemon 2.6 started. (pid:5272 uid:974 gid:974 64-bit)
Apr 28 23:47:09 localhost.localdomain vnstatd[5272]: Info: Monitoring (3): virbr0-nic (1000 Mbit) virbr0 (1000 Mbit) ens160 (10000 Mbit)

View Network Traffic on Rocky Linux

  • View live network traffic using the following command. Replace ens160 with the name of your interface.
vnstat -i ens160 -l

Sample output

Monitoring ens160...    (press CTRL-C to stop)

   rx:         0 bit/s     0 p/s          tx:         0 bit/s      rx:         0 bit/s     0 p/s          tx:         0 bit/s      rx:         0 bit/s     0 p/s          tx:         0 bit/s      rx:         0 bit/s     0 p/s          tx:       360 bit/s      rx:       752 bit/s     1 p/s          tx:       360 bit/s      rx:         0 bit/s     0 p/s          tx:         0 bit/s      rx:     1.17 kbit/s     1 p/s          tx:         0 bit/s      rx:         0 bit/s     0 p/s          tx:         0 bit/s      rx:         0 bit/s     0 p/s          tx:         0 bit/s      rx:     6.19 kbit/s     6 p/s          tx:     6.15 kbit/s      rx:    16.80 kbit/s     7 p/s          tx:    40.61 kbit/s      rx:         0 bit/s     0 p/s          tx:         0 bit/s      rx:         0 bit/s     0 p/s          tx:         0 bit/s      rx:         0 bit/s     0 p/s          tx:         0 bit/s     0 p/s^C


 ens160  /  traffic statistics

                           rx         |       tx
--------------------------------------+------------------
  bytes                     6.08 KiB  |       11.59 KiB
--------------------------------------+------------------
          max           16.80 kbit/s  |    40.61 kbit/s
      average            1.72 kbit/s  |     3.27 kbit/s
          min                0 bit/s  |         0 bit/s
--------------------------------------+------------------
  packets                         32  |              24
--------------------------------------+------------------
          max                  7 p/s  |           5 p/s
      average                  1 p/s  |           0 p/s
          min                  0 p/s  |           0 p/s
--------------------------------------+------------------
  time                    29 seconds
  • Use the command below to view hourly traffic.
vnstat -h

Sample output

ens160  /  hourly

         hour        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2022-04-28
         23:00    539.26 KiB |  300.17 KiB |  839.43 KiB |    2.19 kbit/s
     ------------------------+-------------+-------------+---------------
  • View daily network traffic.
vnstat -d

Sample output

ens160  /  daily

          day        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2022-04-28   539.26 KiB |  300.17 KiB |  839.43 KiB |       80 bit/s
     ------------------------+-------------+-------------+---------------
     estimated       541 KiB |     301 KiB |     842 KiB |
  • View the Monthly Traffic Report using the following command.
vnstat -m

Sample output

ens160  /  monthly

        month        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       2022-04    539.26 KiB |  300.17 KiB |  839.43 KiB |        2 bit/s
     ------------------------+-------------+-------------+---------------
     estimated       --      |     --      |     --      |
  • View Month Traffic Report using the command below .
vnstat --help
  • You have reached the end of our article, congrats! You have learned how to Install vnStat network traffic monitor on Rocky Linux.

Read more about vnStart

Other Tutorials

Configure Static IP Address on Ubuntu 22.04

Install and Configure DHCP client on Rocky Linux

Install DHCP Server on Debian 11

System administrator | Software Developer | DevOps

Leave a Comment