Steps to Install Vnstat on Ubuntu 20.04 LTS With Examples

Vnstat is a free & open source network monitoring tool. It helps to monitor, log and view network statistics over various time periods. It provides summaries on various network interfaces & allows the user to view hourly, daily, monthly statistics.

There are few steps to install vnstat on ubuntu:

Step 1: Update the system.

apt-get update

Step 2: Install Vnstat on system.

apt-get install vnstat

  • To Start & Enable the vnstat.

systemctl start vnstat
systemctl enable vnstat

  • Here is the command output.

[email protected]:/home/ubuntu# systemctl start vnstat
[email protected]:/home/ubuntu# systemctl enable vnstat
Synchronizing state of vnstat.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable vnstat

  • Check the Vnstat version.

vnstat --version

  • Here is the command output.

[email protected]:/home/ubuntu# vnstat --version
vnStat 2.6 by Teemu Toivola <tst at iki dot fi>

Step 3: To setup the interface name.

vim /etc/vnstat.conf

  • Add the interface name.

Interface "eth0"

  • Here is the output.

# vnStat 2.6 config file
##
# default interface (leave empty for automatic selection)
Interface "eth0"
# location of the database directory
DatabaseDir "/var/lib/vnstat"

Step 4: Vnstat syntax & Examples:

  • To Run vnstat command to get summary of network traffic.

vnstat

  • Here is the command output.

[email protected]:/home/ubuntu# vnstat
Database updated: 2021-11-11 08:05:00
eth0 since 2021-11-11
rx: 6.05 MiB tx: 362.15 KiB total: 6.40 MiB
monthly
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
2021-11 6.05 MiB | 362.15 KiB | 6.40 MiB | 60 bit/s
------------------------+-------------+-------------+---------------
estimated 17.30 MiB | -- | 17.30 MiB |
daily
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
today 6.05 MiB | 362.15 KiB | 6.40 MiB | 1.84 kbit/s
------------------------+-------------+-------------+---------------
estimated 17.95 MiB | 1.05 MiB | 19.00 MiB |

  • To list Statistics for a Day.

vnstat -d

  • Here is the command output.

[email protected]:/home/ubuntu# vnstat -d
eth0 / daily
day rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
2021-11-11 6.11 MiB | 478.08 KiB | 6.58 MiB | 1.82 kbit/s
------------------------+-------------+-------------+---------------
estimated 17.43 MiB | 1.33 MiB | 18.76 MiB |

  • To list Statistics for a Month.

vnstat -m

  • Here is the command output.

[email protected]:/home/ubuntu# vnstat -m
eth0 / monthly
month rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
2021-11 6.11 MiB | 478.08 KiB | 6.58 MiB | 61 bit/s
------------------------+-------------+-------------+---------------
estimated 17.30 MiB | -- | 17.30 MiB |

  • To display Statistics for a Hour.

vnstat -h

  • Here is the command output.

[email protected]:/home/ubuntu# vnstat -h
eth0 / hourly
hour rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
2021-11-11
07:00 5.99 MiB | 243.24 KiB | 6.23 MiB | 14.51 kbit/s
08:00 124.95 KiB | 234.85 KiB | 359.80 KiB | 1.96 kbit/s
------------------------+-------------+-------------+---------------

  • To display Statistics in Real Time.

vnstat -l

  • Here is the command output.

[email protected]:/home/ubuntu# vnstat -l
Monitoring eth0... (press CTRL-C to stop)
rx: 208 bit/s 0 p/s tx: 728 bit/s 0 p/s

  • Press CTRL-C to stop.

Monitoring eth0... (press CTRL-C to stop)
rx: 208 bit/s 0 p/s tx: 728 bit/s 0 p/s^C
eth0 / traffic statistics
rx | tx
--------------------------------------+------------------
bytes 1.46 KiB | 3.85 KiB
--------------------------------------+------------------
max 832 bit/s | 1.67 kbit/s
average 332 bit/s | 876 bit/s
min 208 bit/s | 696 bit/s
--------------------------------------+------------------
packets 29 | 25
--------------------------------------+------------------
max 2 p/s | 1 p/s
average 0 p/s | 0 p/s
min 0 p/s | 0 p/s
--------------------------------------+------------------
time 36 seconds

Leave a Reply

Your email address will not be published.