How to Install Vnstat Tool to Monitor Network Traffic in Fedora Linux

This post will guide you how to install vnstat tool to monitor network traffic in your Fedora Linux operating system. How to use vnstat tool to get hourly, weekly, monthly network bandwidth usage through the command line interface of Fedora Linux.

What is vnstat?


Vnstat tool is a network utility for the Linux operating system, and it can be used to keep a log of hourly, daily and monthly network traffic for the selected interface. And vnstat command is a console-based network traffic monitor tool. The traffic information is analyzed from the proc filesystem. That way vnStat can be used even without root permissions.

install vnstat fedora1

Install Vnstat Tool


Before installing vnstat tool, and you can get information about vnstat tool from the command line interface with dnf info command, type:

$ dnf info vnstat

Outputs:

[[email protected] ~]# dnf info vnstat
Last metadata expiration check: 0:02:29 ago on Sun 10 May 2020 08:09:29 PM CST.
Available Packages
Name : vnstat
Version : 1.18
Release : 2.fc30
Architecture : x86_64
Size : 132 k
Source : vnstat-1.18-2.fc30.src.rpm
Repository : fedora
Summary : Console-based network traffic monitor
URL : http://humdi.net/vnstat/
License : GPLv2
Description : vnStat is a console-based network traffic monitor that keeps a log of daily
: network traffic for the selected interface(s). vnStat isn't a packet sniffer.
: The traffic information is analyzed from the /proc file-system, so vnStat can
: be used without root permissions. See the web-page for few 'screenshots'.

From the above output, and you can get the information about the Tool name, Tool Version, or description.

Then you can use the following command to install vnstat on your Fedora Linux, type:

$ sudo dnf install vnstat

Outputs:

[[email protected] ~]# sudo dnf install vnstat
Last metadata expiration check: 0:02:56 ago on Sun 10 May 2020 08:09:29 PM CST.
Dependencies resolved.
================================================================================================================================================================================================================================================
Package Architecture Version Repository Size
================================================================================================================================================================================================================================================
Installing:
vnstat x86_64 1.18-2.fc30 fedora 132 k

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

Total download size: 132 k
Installed size: 462 k
Is this ok [y/N]:y
Downloading Packages:
vnstat-1.18-2.fc30.x86_64.rpm 502 kB/s | 132 kB 00:00 
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 141 kB/s | 132 kB 00:00 
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1 
Running scriptlet: vnstat-1.18-2.fc30.x86_64 1/1 
Installing : vnstat-1.18-2.fc30.x86_64 1/1 
Running scriptlet: vnstat-1.18-2.fc30.x86_64 1/1 
Verifying : vnstat-1.18-2.fc30.x86_64 1/1

Installed:
vnstat-1.18-2.fc30.x86_64

Complete!

Now the vnstat utility should be installed on your Fedora Linux system.

Start and Enable the Vnstat Service


After installed vnstat tool, and you still need to start and enable the server with the following two command:

$ sudo systemctl start vnstat.service
$ sudo systemctl enable vnstat.service

Outputs:

[[email protected] ~]# sudo systemctl start vnstat.service
[[email protected] ~]# sudo systemctl enable vnstat.service
Created symlink /etc/systemd/system/vnstatd.service → /usr/lib/systemd/system/vnstat.service.
Created symlink /etc/systemd/system/multi-user.target.wants/vnstat.service → /usr/lib/systemd/system/vnstat.service.

You can find the current status of the vnstat service with the following command:

$ sudo systemctl status vnstat.service

Outputs:

[[email protected] ~]# sudo systemctl status vnstat.service
vnstat.service - vnStat network traffic monitor
Loaded: loaded (/usr/lib/systemd/system/vnstat.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2020-05-10 20:15:13 CST; 27s ago
Docs: man:vnstatd(1)
man:vnstat(1)
man:vnstat.conf(5)
Main PID: 3662 (vnstatd)
Tasks: 1 (limit: 1793)
Memory: 420.0K
CGroup: /system.slice/vnstat.service
└─3662 /usr/sbin/vnstatd -n

May 10 20:15:13 localhost systemd[1]: Started vnStat network traffic monitor.
May 10 20:15:13 localhost vnstatd[3662]: Zero database found, adding available interfaces...
May 10 20:15:13 localhost vnstatd[3662]: "enp0s3" added with 1000 Mbit bandwidth limit.
May 10 20:15:13 localhost vnstatd[3662]: "virbr0" added with 1000 Mbit bandwidth limit.
May 10 20:15:13 localhost vnstatd[3662]: "virbr0-nic" added with 1000 Mbit bandwidth limit.
May 10 20:15:13 localhost vnstatd[3662]: -> 3 interfaces added.
May 10 20:15:13 localhost vnstatd[3662]: Limits can be modified using the configuration file. See "man vnstat.conf".
May 10 20:15:13 localhost vnstatd[3662]: Unwanted interfaces can be removed from monitoring with "vnstat --delete".
May 10 20:15:13 localhost vnstatd[3662]: Info: vnStat daemon 1.18 started. (pid:3662 uid:977 gid:973)
May 10 20:15:13 localhost vnstatd[3662]: Info: Monitoring: enp0s3 (1000 Mbit) virbr0 (1000 Mbit) virbr0-nic (1000 Mbit)

Display Network Bandwidth Usage for Eth0 interface


Now you can use vnstat tool to display bandwidth usage for a given interface with the following command,type:

$ sudo vnstat -i eth0

Outputs:

[[email protected] ~]# vnstat -i eth0
Database updated: Sun May 10 12:23:36 2020

eth0 since 05/10/2020

rx: 297 KiB tx: 3.48 MiB total: 3.77 MiB

monthly
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
May '20 297 KiB | 3.48 MiB | 3.77 MiB | 0.04 kbit/s
------------------------+-------------+-------------+---------------
estimated -- | -- | -- |

daily
rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
today 297 KiB | 3.48 MiB | 3.77 MiB | 0.69 kbit/s
------------------------+-------------+-------------+---------------
estimated -- | -- | -- |

If you want to get information about interface eht0 with xml format, and just pass to “—xml” option, type:

$ vnstat -i eth0 –xml

Outputs:

[[email protected] ~]# vnstat -i eth0 --xml
<vnstat version="1.15" xmlversion="1">
<interface id="eth0">
<id>eth0</id>
<nick>eth0</nick>
<created><date><year>2020</year><month>05</month><day>10</day></date></created>
<updated><date><year>2020</year><month>05</month><day>10</day></date><time><hour>12</hour><minute>23</minute></time></updated>
<traffic>
<total><rx>297</rx><tx>3568</tx></total>
<days>
<day id="0"><date><year>2020</year><month>05</month><day>10</day></date><rx>297</rx><tx>3568</tx></day>
</days>
<months>
<month id="0"><date><year>2020</year><month>05</month></date><rx>297</rx><tx>3568</tx></month>
</months>
<tops>
</tops>
<hours>
<hour id="12"><date><year>2020</year><month>05</month><day>10</day></date><rx>297</rx><tx>3568</tx></hour>
</hours>
</traffic>
</interface>
</vnstat>

If you want to get information for all monitored interfaces with json format for vnstat command, and you cant pass the “—json” option to vnstat command, type:

$ vnstat -i eth0 –json

Outputs:

[[email protected] ~]# vnstat -i eth0 --json
{"vnstatversion":"1.15","jsonversion":"1","interfaces":[{"id":"eth0","nick":"eth0","created":{"date":{"year":2020,"month":5,"day":10}},"updated":{"date":{"year":2020,"month":5,"day":10},"time":{"hour":12,"minutes":23}},"traffic":{"total":{"rx":297,"tx":3568},"days":[{"id":0,"date":{"year":2020,"month":5,"day":10},"rx":297,"tx":3568}],"months":[{"id":0,"date":{"year":2020,"month":5},"rx":297,"tx":3568}],"tops":[],"hours":[{"id":12,"date":{"year":2020,"month":5,"day":10},"rx":297,"tx":3568}]}}]}

If you want to monitor a default network interface for bandwidth usage with vnstat command, and you need to edit the default configuration file of vnstat located in the /etc/vnstat.conf with your vi or vim text editor:

$ sudo vim /etc/vnstat.conf

And then add the following line into the file:

Interface “eth0”

Save and close the file.

Then you need to restart the vnstat service with the following command:

$ sudo systemctl restart vnstat.service

If you want to monitor daily bandwidth useage, just type:

$ vnstat -d

Outputs:

[[email protected]~]# vnstat -d

eth0 / daily

day rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
05/10/2020 2.26 MiB | 26.04 MiB | 28.31 MiB | 5.06 kbit/s
------------------------+-------------+-------------+---------------
estimated 3 MiB | 49 MiB | 52 MiB |

If you want to get weekly bandwidth usage information, type:

$ vnstat -w

Outputs:

[[email protected]~]# vnstat -w

eth0 / weekly

rx | tx | total | avg. rate
---------------------------+-------------+-------------+---------------
last 7 days 2.26 MiB | 26.04 MiB | 28.31 MiB | 0.41 kbit/s
current week 2.26 MiB | 26.04 MiB | 28.31 MiB | 0.41 kbit/s
---------------------------+-------------+-------------+---------------
estimated 2 MiB | 28 MiB | 30 MiB |

If you want to get the monthly bandwidth usage information, just type:

$ vnstat -m

Outputs:

[[email protected]~]# vnstat -m

eth0 / monthly

month rx | tx | total | avg. rate
------------------------+-------------+-------------+---------------
May '20 2.26 MiB | 26.04 MiB | 28.31 MiB | 0.28 kbit/s
------------------------+-------------+-------------+---------------
estimated 6 MiB | 84 MiB | 90 MiB |

Conclusion


You should know that how to install vnstat tool on your fedora Linux. If you want to see more detailed information about vnstat, you can directly go to its official web site.
Or use the following command:

$ vnstat –help

Outputs:

vnStat 2.6 by Teemu Toivola

-5, --fiveminutes [limit] show 5 minutes
-h, --hours [limit] show hours
-hg, --hoursgraph show hours graph
-d, --days [limit] show days
-m, --months [limit] show months
-y, --years [limit] show years
-t, --top [limit] show top days

-b, --begin set list begin date
-e, --end set list end date

--oneline [mode] show simple parsable format
--json [mode] [limit] show database in json format
--xml [mode] [limit] show database in xml format

-tr, --traffic [time] calculate traffic
-l, --live [mode] show transfer rate in real time
-i, --iface select interface (default: eth0)

Use "--longhelp" or "man vnstat" for complete list of options.

 

You might also like:

Sidebar



back to top