ネットワークトラフィックモニター
$ sudo apt install vnstat
インストールするとデーモン(vnstatd)が動く
$ sudo service vnstat status ● vnstat.service - vnStat network traffic monitor Loaded: loaded (/lib/systemd/system/vnstat.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2021-04-30 00:46:09 JST; 5min ago Docs: man:vnstatd(8) man:vnstat(1) man:vnstat.conf(5) Main PID: 2045411 (vnstatd) Tasks: 1 (limit: 18935) Memory: 808.0K CPU: 184ms CGroup: /system.slice/vnstat.service └─2045411 /usr/sbin/vnstatd -n Apr 30 00:46:10 t430s vnstatd[2045411]: Interface "virbr0" added with 1000 Mbit bandwidth limit. Apr 30 00:46:10 t430s vnstatd[2045411]: Interface "nm-br1" added with 1000 Mbit bandwidth limit. Apr 30 00:46:10 t430s vnstatd[2045411]: Interface "anbox0" added with 1000 Mbit bandwidth limit. Apr 30 00:46:10 t430s vnstatd[2045411]: Interface "lxcbr0" added with 1000 Mbit bandwidth limit. Apr 30 00:46:10 t430s vnstatd[2045411]: Interface "docker0" added with 1000 Mbit bandwidth limit. Apr 30 00:46:10 t430s vnstatd[2045411]: -> 7 new interfaces found. Apr 30 00:46:10 t430s vnstatd[2045411]: Limits can be modified using the configuration file. See "man vnstat.conf". Apr 30 00:46:10 t430s vnstatd[2045411]: Unwanted interfaces can be removed from monitoring with "vnstat --remove". Apr 30 00:46:10 t430s vnstatd[2045411]: Info: vnStat daemon 2.6 started. (pid:2045411 uid:149 gid:165 64-bit) Apr 30 00:46:10 t430s vnstatd[2045411]: Info: Monitoring (7): wlp3s0 (1000 Mbit) virbr0 (1000 Mbit) nm-br1 (1000 Mbit) lxcbr0 (1000 Mbit) enp0s2>
はじめはデータがない
$ vnstat [169/1082] rx / tx / total / estimated anbox0: Not enough data available yet. docker0: Not enough data available yet. enp0s25: Not enough data available yet. lxcbr0: Not enough data available yet. nm-br1: Not enough data available yet. virbr0: Not enough data available yet. wlp3s0: Not enough data available yet.
$ vnstat rx / tx / total / estimated anbox0: Not enough data available yet. docker0: Not enough data available yet. enp0s25: Not enough data available yet. lxcbr0: Not enough data available yet. nm-br1: Not enough data available yet. virbr0: Not enough data available yet. wlp3s0: 2021-04 21.10 MiB / 3.70 MiB / 24.80 MiB / 22.25 MiB today 21.10 MiB / 3.70 MiB / 24.80 MiB / 673.77 MiB
$ vnstat -i wlp3s0 Database updated: 2021-04-30 00:53:40 wlp3s0 since 2021-04-30 rx: 21.10 MiB tx: 3.70 MiB total: 24.80 MiB monthly rx | tx | total | avg. rate ------------------------+-------------+-------------+--------------- 2021-04 21.10 MiB | 3.70 MiB | 24.80 MiB | 82 bit/s ------------------------+-------------+-------------+--------------- estimated 19.78 MiB | 2.47 MiB | 22.25 MiB | daily rx | tx | total | avg. rate ------------------------+-------------+-------------+--------------- today 21.10 MiB | 3.70 MiB | 24.80 MiB | 64.60 kbit/s ------------------------+-------------+-------------+--------------- estimated 573.38 MiB | 100.39 MiB | 673.77 MiB |
複数のインターフェイスを指定
$ vnstat -i usb0+wlp3s0
$ vnstat -i usb0 Error: Interface "usb0" not found in database. $ sudo vnstat --add -i usb0 Adding interface "usb0" for monitoring to database... Restart the vnStat daemon if it is currently running in order to start monitoring "usb0". $ sudo service vnstat restart $ vnstat -i usb0 usb0: Not enough data available yet. $ vnstat -i usb0 -d usb0 / daily day rx | tx | total | avg. rate ------------------------+-------------+-------------+--------------- 2021-04-30 2.03 MiB | 8.18 MiB | 10.21 MiB | 12.90 kbit/s ------------------------+-------------+-------------+--------------- estimated 26.57 MiB | 107.12 MiB | 133.70 MiB |
インターフェイスが切断されているときは disabled
の表示になる.再接続されると disabled
は消えてまたカウントされるよう.
usb0 [disabled]:
リアルタイム
$ vnstat -l Monitoring wlp4s0... (press CTRL-C to stop) rx: 7.39 Mbit/s 632 p/s tx: 234.20 kbit/s 306 p/s^C wlp4s0 / traffic statistics rx | tx --------------------------------------+------------------ bytes 241.31 MiB | 10.07 MiB --------------------------------------+------------------ max 8.33 Mbit/s | 322.19 kbit/s average 322.69 kbit/s | 13.47 kbit/s min 0 bit/s | 0 bit/s --------------------------------------+------------------ packets 187533 | 92295 --------------------------------------+------------------ max 716 p/s | 382 p/s average 29 p/s | 14 p/s min 0 p/s | 0 p/s --------------------------------------+------------------ time 104.55 minutes
1時間毎
$ vnstat -h 3 wlp4s0 / hourly hour rx | tx | total | avg. rate ------------------------+-------------+-------------+--------------- 2021-05-24 05:00 3.28 MiB | 623.99 KiB | 3.88 MiB | 9.05 kbit/s 17:00 510.09 MiB | 7.29 MiB | 517.38 MiB | 1.21 Mbit/s 18:00 286.84 MiB | 8.32 MiB | 295.16 MiB | 1.65 Mbit/s ------------------------+-------------+-------------+---------------
5分毎
$ vnstat -5
日毎
estimated
も表示される.これはこの調子で使い続けるとこのくらいという推測のようで利用時間や利用量が少なかったり,利用状況が変わる場合信頼できない.
$ vnstat -i wlp4s0 -d 1 wlp4s0 / daily day rx | tx | total | avg. rate ------------------------+-------------+-------------+--------------- 2021-05-24 2.13 GiB | 67.15 MiB | 2.20 GiB | 254.79 kbit/s ------------------------+-------------+-------------+--------------- estimated 2.49 GiB | 78.30 MiB | 2.56 GiB |
vNstatの画像出力.Debianではvnstatとは別パッケージの vnstati
に分かれているので導入して利用する.
$ sudo apt install vnstati
usb0の今日
$ vnstati -i usb0 -d -o /tmp/today.png
設定ファイル /etc/vnstat.conf
データベース
$ ls -lA /var/lib/vnstat/ total 68 -rw-r--r-- 1 vnstat vnstat 69632 Apr 30 01:00 vnstat.db
コメント