Install vnStat network traffic monitor on Ubuntu 22.04

This guide is going to take you through on how to Install vnStat network traffic monitor on Ubuntu 22.04. vnStat is a network utility for the Linux operating system which uses command line interface i.e console-based network traffic monitor. vnStat keeps a log of hourly, daily and monthly network traffic for the selected interfaces.

How to Install vnStat network traffic monitor on Ubuntu 22.04

  • Update your packages.
sudo apt update
  • Install vnStat network traffic monitor on Ubuntu 22.04 using the command below.
sudo apt install vnstat

Sample output

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Suggested packages:
  vnstati
The following NEW packages will be installed:
  vnstat
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 103 kB of archives.
After this operation, 309 kB of additional disk space will be used.
Get:1 http://ke.archive.ubuntu.com/ubuntu jammy/universe amd64 vnstat amd64 2.9-1 [103 kB]
Fetched 103 kB in 3s (36.7 kB/s) 
Selecting previously unselected package vnstat.
(Reading database ... 198716 files and directories currently i
nstalled.)
Preparing to unpack .../vnstat_2.9-1_amd64.deb ...
Unpacking vnstat (2.9-1) ...
Setting up vnstat (2.9-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/vn
stat.service → /lib/systemd/system/vnstat.service.
Processing triggers for man-db (2.10.2-1) ...

Configure vnStat on Ubuntu 22.04

  • After the installation, a default database directory for each interface will be created at /var/lib/vnstat. You can list the content of the directory using the command below.
ls -l /var/lib/vnstat/
  • Next, check your interface name using the following command.
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: ens33:  mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 00:0c:29:01:2f:a6 brd ff:ff:ff:ff:ff:ff
    altname enp2s1
  • Add your interface name to be monitored in the vnstat config file. Open the file using the command below.
sudo nano /etc/vnstat.conf
  • Then add your interface name. Remember to replace ens33 with your interface name, save and close the file.
Interface "ens33"
  • Restart vnStat to apply changes.
sudo systemctl restart vnstat
  • Check status using the following command.
sudo systemctl status vnstat.service

Sample output

● vnstat.service - vnStat network traffic monitor
     Loaded: loaded (/lib/systemd/system/vnstat.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-04-28 18:39:19 EAT; 32s ago
       Docs: man:vnstatd(8)
             man:vnstat(1)
             man:vnstat.conf(5)
   Main PID: 6153 (vnstatd)
      Tasks: 1 (limit: 4588)
     Memory: 888.0K
        CPU: 123ms
     CGroup: /system.slice/vnstat.service
             └─6153 /usr/sbin/vnstatd -n

Apr 28 18:39:19 itnixpro-virtual-machine systemd[1]: Started vnStat network traffic monitor.
Apr 28 18:39:19 itnixpro-virtual-machine vnstatd[6153]: Info: vnStat daemon 2.9 started. (pid:6153 uid:128 gid:136 64-bit)
Apr 28 18:39:19 itnixpro-virtual-machine vnstatd[6153]: Info: Monitoring (1): ens33 (1000 Mbit)

View Network Traffic on Ubuntu 22.04

  • To view live network traffic run the following command. Note, replace ens33 with your interface name.
vnstat -i ens33 -l

Sample output

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

   rx:    16.42 kbit/s    10 p/s          tx:    23.69 kbit/s    rx:    30.76 kbit/s    16 p/s          tx:    11.63 kbit/s    rx:     6.54 kbit/s    10 p/s          tx:     7.24 kbit/s    rx:     5.50 kbit/s     9 p/s          tx:     5.45 kbit/s    rx:     5.67 kbit/s    10 p/s          tx:     6.30 kbit/s    rx:    12.34 kbit/s    17 p/s          tx:    15.16 kbit/s    rx:     8.72 kbit/s    12 p/s          tx:    11.86 kbit/s    rx:     4.52 kbit/s     7 p/s          tx:     5.14 kbit/s    rx:     2.82 kbit/s     5 p/s          tx:     2.23 kbit/s    rx:     7.75 kbit/s    12 p/s          tx:     9.12 kbit/s    rx:    19.87 kbit/s    26 p/s          tx:    30.20 kbit/s    rx:   154.54 kbit/s    48 p/s          tx:    57.54 kbit/s    rx:    22.74 Mbit/s  1941 p/s          tx:   619.69 kbit/s    rx:    29.28 Mbit/s  2474 p/s          tx:   602.51 kbit/s    rx:    25.80 Mbit/s  2164 p/s          tx:   316.28 kbit/s    rx:    28.69 Mbit/s  2428 p/s          tx:   312.73 kbit/s    rx:    21.58 Mbit/s  1829 p/s          tx:   333.40 kbit/s    rx:    26.52 Mbit/s  2240 p/s          tx:   431.26 kbit/s    rx:    29.89 Mbit/s  2517 p/s          tx:   382.46 kbit/s    rx:     2.08 Mbit/s   492 p/s          tx:   997.72 kbit/s    rx:   324.10 kbit/s   215 p/s          tx:   352.09 kbit/s    rx:   797.12 kbit/s   185 p/s          tx:   203.75 kbit/s    rx:   982.62 kbit/s   180 p/s          tx:   172.12 kbit/s    rx:   767.96 kbit/s   223 p/s          tx:   747.16 kbit/s    rx:   804.16 kbit/s   887 p/s          tx:     8.94 Mbit/s    rx:     1.62 Mbit/s  2381 p/s          tx:    25.44 Mbit/s    rx:     1.53 Mbit/s  2702 p/s          tx:    29.61 Mbit/s  2565 p/s^C


 ens33  /  traffic statistics

                           rx         |       tx
--------------------------------------+------------------
  bytes                   143.72 MiB  |      125.00 MiB
--------------------------------------+------------------
          max           29.89 Mbit/s  |    33.97 Mbit/s
      average            7.01 Mbit/s  |     6.10 Mbit/s
          min                0 bit/s  |         0 bit/s
--------------------------------------+------------------
  packets                     201213  |          129938
--------------------------------------+------------------
          max               3233 p/s  |        2837 p/s
      average               1169 p/s  |         755 p/s
          min                  0 p/s  |           0 p/s
--------------------------------------+------------------
  time                  2.87 minutes
  • To view hourly traffic use the following command.
vnstat -h

Sample output

ens33  /  hourly

         hour        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2022-04-28
         11:00      1.26 MiB |   19.87 MiB |   21.14 MiB |   49.25 kbit/s
         12:00    173.30 KiB |  125.53 KiB |  298.82 KiB |      679 bit/s
         13:00      3.82 MiB |  921.96 KiB |    4.72 MiB |   11.01 kbit/s
         14:00      6.73 KiB |    6.80 KiB |   13.53 KiB |       30 bit/s
         15:00      3.65 MiB |    1.33 MiB |    4.98 MiB |   11.61 kbit/s
         16:00    369.11 KiB |  231.65 KiB |  600.76 KiB |    1.37 kbit/s
         17:00    668.64 KiB |  254.28 KiB |  922.92 KiB |    2.10 kbit/s
         18:00    148.60 MiB |  195.28 MiB |  343.88 MiB |  961.55 kbit/s
     ------------------------+-------------+-------------+---------------
  • View daily network traffic using the command below.
vnstat -d

Sample output

ens33  /  daily

          day        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
     2022-04-28   225.60 MiB |  249.81 MiB |  475.41 MiB |   58.56 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated    286.17 MiB |  316.90 MiB |  603.07 MiB |
  • View the Monthly Traffic Report
vnstat -m

Sample output

ens33  /  monthly

        month        rx      |     tx      |    total    |   avg. rate
     ------------------------+-------------+-------------+---------------
       2022-04    225.60 MiB |  249.81 MiB |  475.41 MiB |    1.66 kbit/s
     ------------------------+-------------+-------------+---------------
     estimated    242.25 MiB |  269.44 MiB |  511.69 MiB |
  • To check more examples, run the help command below.
vnstat --help
  • That marks the end of our article, Cheers. You have learned how to Install vnStat network traffic monitor on Ubuntu 22.04.

Read more about vnStart

Other Tutorials

Install DHCP Server on Debian 11

How to Configure DHCP Client on Ubuntu 22.04

Configure Static IP Address on Ubuntu 22.04

System administrator | Software Developer | DevOps

Leave a Comment