【Linux】vmstatコマンド

 【1】vmstatコマンド

* 「主メモリーの空き容量」「CPUの動作状況」などを表示する
* vmstat = Virtual Memory STATistics

 【2】構文

vmstat 【オプション】 【更新回数】

 1)主なオプション

# オプション(省略版) オプション 説明
1 -a --active アクティブ/非アクティブなメモリ量
2 -s --stats 1項目1行でメモリの統計情報とイベントカウンタを表示
3 -S 単位 --unit 単位 単位をk,K,m,Mで指定する(kは1000、Kは1024、mは1000000、Mは1024*1024 [Byte])
4 -n 数字[秒] --one-header 指定秒数で更新(vmstat -n 60)

ヘルプの出力結果

 -a, --active           active/inactive memory
 -f, --forks            number of forks since boot
 -m, --slabs            slabinfo
 -n, --one-header       do not redisplay header
 -s, --stats            event counter statistics
 -d, --disk             disk statistics
 -D, --disk-sum         summarize disk statistics
 -p, --partition <dev>  partition specific statistics
 -S, --unit <char>      define display unit
 -w, --wide             wide output

 -h, --help     display this help and exit
 -V, --version  output version information and exit

 【3】コマンド例

例1:オプションなし

vmstat

例2 : 5秒間隔で100回表示

vmstat 5 100

例3 : 60秒(1分)間隔で更新した結果を「vmstat.log」に追記

vmstat -n 60 > vmstat.log

 【4】出力結果・説明

例1 : 「vmstat」実行例

$ vmstat

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0  64364   6608  10072  85204   28  563  4055   701  252 1047  9  9 76  5  0

  procs

* アクティブなプロセスに関する統計情報
# 項目 説明
1 r 実行待ち状態にあるプロセス数
2 b 割り込み不可能なスリープ状態にあるプロセス数

  memory

* メモリ使用量と使用可能量に関する情報
# 項目 説明
1 swpd 仮想メモリ
2 free 空きメモリ量 [KB]
3 buff バッファに使用しているメモリ量 [KB]
4 cache キャッシュに使用しているメモリ量

 swap

* スワップに関する統計情報
# 項目 説明
1 si ディスクからスワップインしているメモリ量 [KB/秒]
2 so ディスクにスワップしているメモリ量 [KB/秒]

 io

* メモリ使用量と使用可能量に関する情報
# 項目 説明
1 bi ブロック・デバイスから受け取ったブロック数 [ブロック/秒]
2 bo ブロック・デバイスに送られたブロック数 [ブロック/秒]

 system

* システム全体の割り込みおよびコンテキストの切替レート
# 項目 説明
1 in 毎秒の割り込み回数
2 cs 毎秒のコンテキスト・スイッチ回数

 cpu

* CPU使用量の割合
# 項目 説明
1 us ユーザー時間の割合(プログラム自体の実行に費やされた時間)
2 sy システム時間の割合(OSのコードが実行された時間)
3 id アイドル時間(何もしてない待機状態)の割合
4 wa IO待ち時間の割合
5 st 仮想環境で実行している際、ホストOSに割当ててもらえなかった時間の割合

例2 : 「vmstat -s」実行例

$ vmstat -s

       492464 K total memory
       484632 K used memory
       178464 K active memory
       177824 K inactive memory
         7832 K free memory
        15776 K buffer memory
        75440 K swap cache
       901116 K total swap
        90540 K used swap
       810576 K free swap
         2158 non-nice user cpu ticks
           20 nice user cpu ticks
...

 【5】vmstatコマンドあれこれ

 1)ファイル出力するには

http://tech.clickyourstyle.com/articles/5

が参考になる

vmstat -n 60 | gawk '{ print strftime("%Y/%m/%d %H:%M:%S"), $0 } { fflush() }' > vmstat_output.log

# -n : ヘッダーなし

 参考文献

http://www.atmarkit.co.jp/ait/articles/1707/13/news015.html
http://itpro.nikkeibp.co.jp/article/COLUMN/20060228/230989/
https://orebibou.com/2015/07/vmstat%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%81%A7%E8%A6%9A%E3%81%88%E3%81%A6%E3%81%8A%E3%81%8D%E3%81%9F%E3%81%84%E4%BD%BF%E3%81%84%E6%96%B98%E5%80%8B/

 関連記事

Linux ~ パフォーマンスに関わるコマンド ~
https://dk521123.hatenablog.com/entry/2015/02/21/112554