【Linux】 vmstatコマンド

  ■ vmstatコマンド

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

 

  ■ 構文

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

  主なオプション

`# `オプション(省略版) `オプション `説明
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

  コマンド例

例1
vmstat
例2 : 5秒間隔で100回表示
vmstat 5 100
例3 : 60秒(1分)間隔で更新した結果を「vmstat.log」に追記
vmstat -n 60 > vmstat.log

 

  ■ 出力結果・説明

例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
         1550 system cpu ticks
       356447 idle cpu ticks
         1360 IO-wait cpu ticks
            0 IRQ cpu ticks
           42 softirq cpu ticks
            0 stolen cpu ticks
       746741 pages paged in
       135000 pages paged out
         2726 pages swapped in
        24050 pages swapped out
       170442 interrupts
       410574 CPU context switches
   1512127624 boot time
         1903 forks

 

  ■ vmstatコマンドあれこれ

  ファイル出力するには

http://tech.clickyourstyle.com/articles/5
が参考になる
vmstat -n 60 | gawk '{ print strftime("%Y/%m/%d %H:%M:%S"), $0 } { fflush() }' > vmstat_output.log

# -n : ヘッダーなし

 

 

  関連記事

  パフォーマンスに関わるコマンド ~ Linux編 ~

https://blogs.yahoo.co.jp/dk521123/34615658.html