2018-02-25
Linux で、システムに負荷がかかったときの、CPU負荷 / メモリ使用量 / ディスク負荷 / ネットワーク負荷 / .. を知り、システムの規模 (CPUコア数 / メモリ容量 / ディスクの種類? / ..) を決める目安としたい。
それを知る手段 (コマンド) は、あらためて調べると様々なものがあるようだが..
top uptime ps vmstat iostat netstat ifstat vnstat ..
システム負荷を知るのに、まず
vmstat は基本的なコマンドだが、ネットワーク負荷を知ることはできない。
ネットワーク負荷を知るには netstat が使えそうだ
(FreeBSD や NetBSD や CentOS では)。
ということはこれらのコマンドを同時に立ち上げて..
他に必要なものは..
ひとまず vmstat の出力のどの項目を見たら何がどのように分かるか..
ということまで考えた所で、dstat というツールが Linux では使えるということを知った。
DAG: Dstat: Versatile resource statistics tool
dstat は、使い方や表示は vmstat (システム負荷に主に関係する代表的な測定項目を表示間隔(秒)を指定して1回に1行ずつ表示していく) によく似ているが、他にも netstat や iostat 等々で見られるような様々な項目も、コマンドラインで指定することで表示できる。
単に引数を付けずに実行すると、-cdngy を指定したのと同等となり、1秒おきに、以下の情報を表示する。
[nsmrtks@hoge ~]$ dstat
You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read writ| recv send| in out | int csw
1 0 99 0 0 0|3180B 17k| 0 0 | 0 0 | 62 109
1 0 99 0 0 0| 0 0 | 394B 988B| 0 0 | 57 108
0 1 99 0 0 0| 0 0 | 394B 444B| 0 0 | 55 95
0 0 100 0 0 0| 0 28k| 394B 444B| 0 0 | 57 103
〜
終了するには Ctrl-C を押す。
最後に数値を指定すると、1秒ごとに行の表示を更新した後、指定した数値の秒数後に、その間の平均値を表示して、次の行に移る。
[nsmrtks@hoge ~]$ dstat -a 5
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read writ| recv send| in out | int csw
1 0 99 0 0 0|3174B 18k| 0 0 | 0 0 | 62 108
0 0 100 0 0 0| 0 0 | 387B 551B| 0 0 | 37 65
1 0 99 0 0 0| 0 0 | 387B 469B| 0 0 | 45 66
0 0 100 0 0 0| 0 0 | 356B 469B| 0 0 | 40 70
〜
-a (-cdngy) に加え、さらに以下を指定してみる。
指定したオプションの順番で (左から右に) 表示される。
なお、ターミナルの横幅が小さいと、折り返すのではなく、表示されないことがある。
[nsmrtks@hoge ~]$ dstat -tlpafms 5
----system---- ---load-avg--- ---procs--- -------cpu0-usage------ --dsk/vda-- net/br-4107-net/docker0-net/docker_---net/eth0----net/eth1----net/eth2--net/veth971-net/veth9df-net/vethad8 ---paging-- ---system-- ------memory-usage----- ----swap---
time | 1m 5m 15m |run blk new|usr sys idl wai hiq siq| read writ| recv send: recv send: recv send: recv send: recv send: recv send: recv send: recv send: recv send| in out | int csw | used buff cach free| used free
20-02 15:30:25| 0 0.02 0.09|0.0 0 0.1| 1 0 99 0 0 0|3174B 18k| 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 | 0 0 | 62 108 | 656M 4096B 972M 212M| 0 0
20-02 15:30:30| 0 0.02 0.09| 0 0 0| 0 0 99 0 0 0| 0 819B| 0 0 : 0 0 : 0 0 : 0 0 : 330B 1287B: 60B 0 : 0 0 : 0 0 : 0 0 | 0 0 | 40 68 | 656M 4096B 972M 212M| 0 0
20-02 15:30:35| 0 0.02 0.09| 0 0 0| 0 0 100 0 0 0| 0 4915B| 0 0 : 0 0 : 0 0 : 0 0 : 438B 1017B: 36B 0 : 0 0 : 0 0 : 0 0 | 0 0 | 41 67 | 656M 4096B 972M 212M| 0 0
20-02 15:30:40| 0 0.02 0.09| 0 0 0| 0 0 99 0 0 0| 0 0 | 0 0 : 0 0 : 0 0 : 0 0 : 331B 969B: 12B 0 : 0 0 : 0 0 : 0 0 | 0 0 | 37 63 | 656M 4096B 972M 212M| 0 0
〜
上を見ると、swap の、used もさることながら、free が 0 になっているということは、このシステムはスワップ無しで動いているらしい..
--output file を付けると、画面の表示はそのまま、file にも保存される。 CSV 形式で保存される。
[nsmrtks@hoge ~]$ dstat -tlpafms --output dstat-tlpafms5.csv 5
----system---- ---load-avg--- ---procs--- -------cpu0-usage------ --dsk/vda-- net/br-4107-net/docker0-net/docker_---net/eth0----net/eth1----net/eth2--net/veth971-net/veth9df-net/vethad8 ---paging-- ---system-- ------memory-usage----- ----swap---
time | 1m 5m 15m |run blk new|usr sys idl wai hiq siq| read writ| recv send: recv send: recv send: recv send: recv send: recv send: recv send: recv send: recv send| in out | int csw | used buff cach free| used free
20-02 16:37:37| 0 0.01 0.05|0.0 0 0.1| 1 0 99 0 0 0|3169B 18k| 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 : 0 0 | 0 0 | 62 108 | 656M 4096B 974M 209M| 0 0
20-02 16:37:42| 0 0.01 0.05| 0 0 0| 0 0 99 0 0 0| 0 25k| 0 0 : 0 0 : 0 0 : 0 0 : 309B 1265B: 24B 0 : 0 0 : 0 0 : 0 0 | 0 0 | 59 106 | 656M 4096B 974M 209M| 0 0
20-02 16:37:47| 0 0.01 0.05| 0 0 0| 0 0 99 0 0 0| 0 0 | 0 0 : 0 0 : 0 0 : 0 0 : 423B 974B: 96B 0 : 0 0 : 0 0 : 0 0 | 0 0 | 60 104 | 656M 4096B 974M 209M| 0 0
20-02 16:37:52| 0 0.01 0.05| 0 0 0| 0 0 100 0 0 0| 0 0 | 0 0 : 0 0 : 0 0 : 0 0 : 424B 973B: 24B 0 : 0 0 : 0 0 : 0 0 | 0 0 | 58 103 | 656M 4096B 974M 209M| 0 0
〜
dstat-tlpafms5.csv
"Dstat 0.7.2 CSV output"
"Author:","Dag Wieers <dag@wieers.com>",,,,"URL:","http://dag.wieers.com/home-made/dstat/"
"Host:","hoge.novalocal",,,,"User:","nsmrtks"
"Cmdline:","dstat -tlpafms --output dstat-tlpafms5.csv 5",,,,"Date:","20 Feb 2018 16:37:37 JST"
"system","load avg",,,"procs",,,"cpu0 usage",,,,,,"dsk/vda",,"net/br-41073193720c",,"net/docker0",,"net/docker_gwbridge",,"net/eth
0",,"net/eth1",,"net/eth2",,"net/veth971cb7a",,"net/veth9df672f",,"net/vethad88402",,"paging",,"system",,"memory usage",,,,"swap",
"time","1m","5m","15m","run","blk","new","usr","sys","idl","wai","hiq","siq","read","writ","recv","send","recv","send","recv","sen
d","recv","send","recv","send","recv","send","recv","send","recv","send","recv","send","in","out","int","csw","used","buff","cach"
,"free","used","free"
20-02 16:37:37,0.0,0.010,0.050,0.000,0.0,0.103,0.834,0.222,98.604,0.337,0.0,0.002,3169.403,17973.814,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0
.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,62.273,108.401,687935488.0,4096.0,1021595648.0,219521024.0,0.0,0.0
20-02 16:37:42,0.0,0.010,0.050,0.0,0.0,0.0,0.400,0.200,99.400,0.0,0.0,0.0,0.0,25190.400,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,308.800,12
64.800,24.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,58.600,106.400,687931392.0,4096.0,1021599744.0,219521024.0,0.0,0.0
20-02 16:37:47,0.0,0.010,0.050,0.0,0.0,0.0,0.401,0.200,99.399,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,423.200,974.400,
96.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,59.800,104.200,687931392.0,4096.0,1021599744.0,219521024.0,0.0,0.0
20-02 16:37:52,0.0,0.010,0.050,0.0,0.0,0.0,0.401,0.0,99.599,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,424.400,972.800,24
.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,58.200,103.0,687931392.0,4096.0,1021599744.0,219521024.0,0.0,0.0
この、最初の4行を取り出して整形するとこんな感じで、
Dstat 0.7.2 CSV output Author: Dag Wieers <dag@wieers.com> URL: http://dag.wieers.com/home-made/dstat/ Host: hoge.novalocal User: nsmrtks Cmdline: dstat -tlpafms --output dstat-tlpafms5.csv 5 Date: 20 Feb 2018 16:37:37 JST
最初の5行を取り除くとこんな感じであろう。
system | load avg | procs | cpu0 usage | dsk/vda | net/br- 410731 93720c |
net/ docker0 |
net/ docker_ gwbridge |
net/ eth0 |
net/ eth1 |
net/ eth2 |
net/ veth 971cb7a |
net/ veth 9df672f |
net/ veth ad88402 |
paging | system | memory usage | swap | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
time | 1m | 5m | 15m | run | blk | new | usr | sys | idl | wai | hiq | siq | read | writ | recv | send | recv | send | recv | send | recv | send | recv | send | recv | send | recv | send | recv | send | recv | send | in | out | int | csw | used | buff | cach | free | used | free |
20-02 16:37:37 |
0.0 | 0.010 | 0.050 | 0 .000 | 0.0 | 0 .103 |
0 .834 | 0 .222 | 98 .604 | 0 .337 |
0.0 | 0 .002 |
3169 .403 | 17973 .814 |
0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 62 .273 | 108 .401 |
687 935488.0 |
4096.0 | 1021 595648.0 | 219 521024.0 |
0.0 | 0.0 |
20-02 16:37:42 |
0.0 | 0.010 | 0.050 | 0.0 | 0.0 | 0.0 | 0 .400 | 0 .200 | 99 .400 | 0.0 | 0.0 | 0.0 | 0.0 | 25190 .400 |
0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 308 .800 | 1264 .800 |
24.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 58 .600 | 106 .400 |
687 931392.0 |
4096.0 | 1021 599744.0 | 219 521024.0 |
0.0 | 0.0 |
20-02 16:37:47 |
0.0 | 0.010 | 0.050 | 0.0 | 0.0 | 0.0 | 0 .401 | 0 .200 | 99 .399 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 423 .200 | 974 .400 |
96.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 59 .800 | 104 .200 |
687 931392.0 |
4096.0 | 1021 599744.0 | 219 521024.0 |
0.0 | 0.0 |
20-02 16:37:52 |
0.0 | 0.010 | 0.050 | 0.0 | 0.0 | 0.0 | 0 .401 | 0.0 | 99 .599 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 424 .400 | 972 .800 |
24.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 0.0 | 58 .200 | 103 .0 |
687 931392.0 |
4096.0 | 1021 599744.0 | 219 521024.0 |
0.0 | 0.0 |