サーバーのリソース使用状況表示
サーバリソース(memory,swap,cpu等)の使用状況を一秒置きに表示する。
vmstat -n 1
上記コマンドにより標準出力にて下記が表示。
[root@XXX ~]# vmstat -n 1 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 116 211692 252808 3047644 0 0 2 14 3 4 0 0 100 0 0 0 0 116 211692 252808 3047644 0 0 0 0 1025 299 0 0 100 0 0 0 0 116 211692 252808 3047644 0 0 0 0 1005 278 0 0 100 0 0 0 0 116 211692 252808 3047644 0 0 0 0 1022 313 0 0 100 0 0 ※一秒置きに表示
表示間隔を変更したい場合は
vmstat -n ○<-ここに希望の数字を入力。
5秒置きの場合は
vmstat -n 5
コマンドを実行しておくことで都度状況が確認できる。
テキストファイルに出力する事で、ログファイル的なものも作成可能。
その場合、実行時間が付いていると便利なので追加。
vmstat -n 1 | (awk '{now=strftime("%Y-%m-%d %T "); print now $0}' > vmstat.txt )
※コマンドの実行結果がファイル(vmstat.txt)へ書き出されるまで15秒程度の時間がかかります。
[root@XXX hogeuser]# date(コマンド実行時刻) 2011年 11月 18日 金曜日 18:54:09 JST [root@XXX hogeuser]# vmstat -n 1 | (awk '{now=strftime("%Y-%m-%d %T "); print now $0}' > vmstat.txt ) ※実行終了 [root@XXX hogeuser]# date(コマンド終了時刻) 2011年 11月 18日 金曜日 18:56:21 JST [root@XXX hogeuser]# cat vmstat.txt 2011-11-18 18:54:11 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ 2011-11-18 18:54:11 r b swpd free buff cache si so bi bo in cs us sy id wa st 2011-11-18 18:54:11 1 0 116 210664 252888 3048384 0 0 2 14 4 4 0 0 100 0 0 2011-11-18 18:54:12 0 0 116 210664 252888 3048384 0 0 0 0 1024 313 0 0 100 0 0 2011-11-18 18:54:13 0 0 116 210664 252888 3048384 0 0 0 0 1003 311 0 0 100 0 0 (省略) 2011-11-18 18:56:07 1 0 116 210540 252888 3048392 0 0 0 0 1003 279 0 0 100 0 0 2011-11-18 18:56:08 0 0 116 2[EOF]
※18:56:07〜18:56:21までの情報が書き出されていない。
コマンド実行を終了した場合、終了時刻の-15秒程度までの結果しかファイルに書きだされていない。
確認に必要な時刻+30秒程度は動作させたのち、コマンドを終了するのが安全。
実行時間を付けたコマンドを標準出力に出力して、ターミナルでログを取れば問題ないです。