This article is converted by SimpRead, original source xujinzh.github.io
Besides the common tools for monitoring Linux server network traffic such as ifconfig, nload, iftop, etc., these tools only show total traffic information, and monitoring data will be reset after the server restarts.
Besides the common Linux server network traffic monitoring tools like ifconfig, nload, iftop, etc., which only provide total traffic information and reset their data after the server restarts, this article introduces vnstat. It can save monitoring data to a database and display traffic statistics as needed.
sudo apt update
sudo apt install vnstat vnstati
After installation, there is a configuration file: /etc/vnstat.conf, which contains parameters such as Interface. This parameter by default automatically monitors the network interface to be tracked. MonthRotate is the monthly traffic billing date, i.e., the date when the monthly traffic is recalculated, defaulting to the 1st day of each month.
To generate a database file for the network interface:
vnstat -i eth0 --dbdir /disk0/vnstat
Common commands:
vnstat
vnstat -l -i eth0
vnstat -5
vnstat -h
vnstat -hg
vnstat -d
vnstat -m
vnstat -h --xml
vnstat -h --json
vnstat -h -b 2023-03-01 -e 2023-03-04
vnstati -i eth0 --months --output month-network-traffic-stats.png
Explanation of output:
- rx: receive
- tx: transmit
- total: total
- estimated: estimated
For more details, use the command vnstat --help or man vnstat:
vnStat 2.6 by Teemu Toivola <tst at iki dot fi>
-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 <date> set list begin date
-e, --end <date> 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 <interface> select interface
Use "--longhelp" or "man vnstat" for complete list of options.