本文由 简悦 SimpRead 转码, 原文地址 xujinzh.github.io
Linux 服务器网络流量监测工具除了常见的 ifconfig, nload, iftop 等,但只有总流量信息,且当服务器重启后,监测数据会重新统计。
Linux 服务器网络流量监测工具除了常见的 ifconfig
, nload
, iftop
等,但只有总流量信息,且当服务器重启后,监测数据会重新统计。本篇介绍 vnstat
,它能够把监测数据保存到数据库中,可以根据需要显示流量统计信息。
sudo apt update
sudo apt install vnstat vnstati
安装完成后有配置文件:/etc/vnstat.conf
,里面配置参数,如 Interface
该参数默认会自动监测需要监控的网卡,MonthRotat
为每月流量结算日期,即每月流量重新计算的日期,默认为每月 1 号。
对网卡生产数据库文件:
vnstat -i eth0 --dbdir /disk0/vnstat
常用命令:
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
输出结果解释:
- rx:接收 (receive)
- tx:发送(transport)
- total:总计
- estimated:估计
更多请使用命令 vnstat --help
查看,或者 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.