vnStat is a console-based network traffic monitoring tool for Linux. It provides network statistics for various time periods.
VnStat uses the network interface statistics provided by the kernel as the source of information - ie from the proc and sys filesystem. It keeps a log of hourly, daily, and monthly network traffic for the selected interface(s).
In this tutorial, we learn how to install and use vnStat in Ubuntu.
Install VnStat on Ubuntu
VnStat is available in the repository of Ubuntu, use the apt command to install it. It is also available as a source file that you can download and compile.
First update the Ubuntu, type:
$ sudo apt update
Now to Install Vnstat on Ubuntu, type:
$ sudo apt install vnstat
The latest version is available at this time of writing is vnStat 2.6.
How to use vnStat
vnStat has two components - vnstatd daemon and vnstat command. It has a configuration file at /etc/vnstat.conf - can change output style, change units, date formats, and more. VnStat is by default installed in /usr/bin/vnstat.
vnstatd is responsible for monitoring and updating the VnStat database. VnStat database is located at /var/lib/vnstat/.
vnstat command is the CLI tool to query network traffic.
Now let's check how to use vnstat command to check network traffic
1. Display network traffic summary of the default interface
In the vnStat output, rx (receive) denotes the MiB data downloaded and tx (transmit) denotes the upload.
If the vnStat output with "Not enough data available yet", wait for some more time for the daemon to grab data.
Instead to see the output in a short summary use -s option.
2. To see statistics of a specific interface:
$ vnstat -i eth0
3. To display the hourly statistics of eth0:
$ vnstat -i eth0 -h
4. To show daily statistics of eth0:
$ vnstat -i eth0 -d
5. To show monthly statistics of eth0:
$ vnstat -i eth0 -m
6. To see all-time top 10 traffic days:
$ vnstat -t $ vnstat -i eth0 -t
7. Calculate average traffic passing through in given time seconds:
$ vnstat -tr $ vnstat -i eth0 -tr
8. Monitor the traffic in real-time:
$ vnstat -l
In this tutorial, we learned how to install and use vnStat on Ubuntu. For more information check the man vnstat page.
vnStati is the GUI version of vnStat. VnStati comes along with vnStat package, so no need to install it seperately. It can generate vnStat output in an image and also in a graphical format.
If you have any feedback and suggestion please comment below.