Posted on August 1, 2023 by nexonhost
How To Use Vnstat Command.
vnStat is a network utility for the Linux operating system. It is a console-based network traffic monitor that keeps a log of hourly, daily, and monthly network traffic for the selected interface(s).
![Nexonhost Dedicated Servers , Virtual Servers](https://nexonhost.com/wp-content/uploads/2023/07/desktop-pc-monitor-photo-javascript-functions-variables-objects-project-managers-work-new-idea-future-technology-creation-process-768x512.jpg)
Installing vnstat on Linux
For RedHat based Linux use:
yum install vnstat
For ubuntu or debian Linux use:
apt install vnstat
To get basic stats of all network interfaces.
vnstat
This command will print all the basic stats of the network interfaces connected to the system.
To monitor a specific interface.
vnstat -i wlo1
This will monitor and display the stats of the specified interface that is wlo1.
To get the daily stats of an interface.
vnstat -d -i wlo1
This will print the daily stats of the specified interface which is wlo1.
To get the hourly stats of an interface.
vnstat -h -i wlo1
This will print the hourly stats of the specified interface which is wlo1.
To display the monthly stats of a interface.
vnstat -m -i wlo1
This command will display the monthly stats of the specified interface.
To save output to a XML file
vnstat --xml -i wlo1 >output.xml
The command will create an XML file with name output.xml and will have the output of the command in XML format.
To save output to a JSON file
vnstat --json -i wlo1 >output.json
This command will create a JSON file with name output.json and will have the output of the command in JSON format.
To save output to a text file.
vnstat --oneline -i wlo1 >output.txt
This command will create a text file with name output.txt and will have the output in a one-line format.
To calculate traffic on the current interface.
vnstat -tr
This command will display the traffic on the current network interface in use.
To display vnstat help.
vnstat --help
This command will display the vnstat help section.
Check the traffic on the Ethernet interface (e.g., eth0):
vnstat -i eth0
This command will display statistics about network traffic for the “eth0” interface, including total traffic (rx and tx), daily traffic, current month, and previous months.
Display the total traffic for the current month on all interfaces:
vnstat -m
This command will display the total traffic for the current month for each available network interface on the system.
Display the total traffic for a specific period (e.g., last 7 days):
vnstat -d -i eth0 --days 7
This command will display the total traffic on the “eth0” interface for the last 7 days.
Display the total traffic for the current year on a specific interface:
vnstat -y -i wlan0
This command will display the total traffic on the “wlan0” interface for the current year.
Display the monthly traffic on a specific interface in a human-readable format:
vnstat -m -i eth0 --style 0
This command will display the monthly traffic on the “eth0” interface in a human-readable format, making it easier to read.
These are just a few examples of VnStat commands, and the utility has many other options and arguments that you can explore by consulting its manual page with the command:
man vnstat
Please note that to get the most accurate and up-to-date statistics, VnStat needs to be set up to run in the background and update the data periodically. Also, make sure you have superuser privileges (sudo) to run certain commands, especially those that request information about all network interfaces available on the system.