Hatena::ブログ(Diary)

ablog このページをアンテナに追加 RSSフィード Twitter

2018-01-08

vmstat でタイムスタンプを表示するAdd Star

vmstat: Support for timestamps with '-t' & fix for '-wd'

From now the vmstat can append a timestamp to each line in the

VMSTAT and DISKSTAT mode. You can achieve that with the '-t'

switch.

The '-w' switch now works in the DISKSTAT mode too.

vmstat: Support for timestamps with '-t' & fix for '-wd' (4fcd56bf) ? Commits ? procps-ng / procps ? GitLab

これ以降 vmstat は -t オプションタイムスタンプを表示できるようになっている。

$ vmstat -V
procps version 3.2.8
$ vmstat -t 5
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------ ---timestamp---
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 59579072 735596 280408    0    0     0     0   10    2  0  0 100  0  0	2018-01-08 07:33:15 UTC
 0  0      0 59579072 735596 280408    0    0     0     0   30   34  0  0 100  0  0	2018-01-08 07:33:20 UTC
 0  0      0 59578932 735596 280408    0    0     0     0   29   34  0  0 100  0  0	2018-01-08 07:33:25 UTC

この機能追加が入る前のバージョンの vmstat でも以下のように awk などでタイムスタンプを追加してやるとよい。

$ vmstat 5|awk '{print strftime("%Y-%m-%d %H:%M:%S"), $0}'
2018-01-08 07:35:47 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
2018-01-08 07:35:47  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
2018-01-08 07:35:47  1  0      0 59579072 735668 280420    0    0     0     0   10    2  0  0 100  0  0
2018-01-08 07:35:52  0  0      0 59579072 735668 280420    0    0     0     5   69   68  0  0 100  0  0
2018-01-08 07:35:57  0  0      0 59579072 735668 280420    0    0     0     0   32   38  0  0 100  0  0

なお、パイプで tee コマンドに渡すなどすると、awk がバッファリングしてすぐに表示されないので、"fflush()" でフラッシュしてやる。詳しくは下記 URL 参照。

$ vmstat 5|awk '{print strftime("%Y-%m-%d %H:%M:%S"), $0;fflush()}'|tee -a vmstat_20180109.log

vmstat を含む procps プロジェクトのソースコードprocps-ng / procps ? GitLab で読むことができる。


参考

スパム対策のためのダミーです。もし見えても何も入力しないでください
ゲスト


画像認証

トラックバック - http://d.hatena.ne.jp/yohei-a/20180108/1515396847