vnstat 是一款实用的网卡流量统计工具,与其他流量监控工具不同,vnstat 会将统计数据写入数据库,还可以 daemon 形式运行在后台。

安装

$ sudo apt install vnstat

查看所有网卡流量数据

$ vnstat

                      rx      /      tx      /     total    /   estimated
 wlp58s0:
       9月 '18    141.76 MiB  /   19.55 MiB  /  161.30 MiB  /  163.00 MiB
         today    141.76 MiB  /   19.55 MiB  /  161.30 MiB  /     247 MiB

 enp0s31f6: Not enough data available yet.

实时显示网卡流量

查看网卡信息:

$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s31f6: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether c8:5b:76:70:4f:54 brd ff:ff:ff:ff:ff:ff
3: wlp58s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 34:13:e8:5f:3d:95 brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.100/24 brd 192.168.8.255 scope global dynamic noprefixroute wlp58s0
       valid_lft 72128sec preferred_lft 72128sec
    inet6 fe80::4ac9:13aa:62cc:37fa/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

完整命令:

$ vnstat --iface wlp58s0 --live --rateunit

简化参数:

$ vnstat -i wlp58s0 -l -ru
Monitoring wlp58s0...    (press CTRL-C to stop)

   rx:      0.00 KiB/s     0 p/s          tx:      0.00 KiB/s     0 p/s^C


 wlp58s0  /  traffic statistics

                           rx         |       tx
--------------------------------------+------------------
  bytes                    91.29 MiB  |        2.22 MiB
--------------------------------------+------------------
          max           811.62 KiB/s  |     23.15 KiB/s
      average           315.82 KiB/s  |      7.68 KiB/s
          min             0.00 KiB/s  |      0.00 KiB/s
--------------------------------------+------------------
  packets                      66263  |           23376
--------------------------------------+------------------
          max                577 p/s  |         239 p/s
      average                223 p/s  |          78 p/s
          min                  0 p/s  |           0 p/s
--------------------------------------+------------------
  time                  4.93 minutes

  • rx - receive 即下行流量
  • tx - transport 即上行流量