2018-01-08
vmstat でタイムスタンプを表示する
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'
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
リンク元
- 51 https://www.google.co.jp/
- 11 http://www.google.co.uk/url?sa=t&source=web&cd=1
- 8 http://b.hatena.ne.jp/
- 7 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwiF283c7cfYAhWHVZQKHZlLBG0QFggnMAA&url=http://d.hatena.ne.jp/yohei-a/20110601/1306891897&usg=AOvVaw2iH5OJ1PVe4gx1qrftpIul
- 3 http://b.hatena.ne.jp/?iosapp=1
- 3 http://d.hatena.ne.jp/
- 3 http://search.minakoe.jp/rsss/rsss.asp?qry=domain:hatena&qry=domain:hatena&multi=1
- 2 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0ahUKEwi11cDkiMjYAhXLjZQKHV4_D7UQFgg4MAE&url=http://d.hatena.ne.jp/yohei-a/20140103/1388767360&usg=AOvVaw1RE0GItmpa_1LWLfZySVNe
- 2 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=6&ved=0ahUKEwj5waq79cfYAhVJOrwKHeicBDUQFghGMAU&url=http://d.hatena.ne.jp/yohei-a/20090531/1243771621&usg=AOvVaw1-en5mxasgDVAG9tgUYxT5
- 1 http://b.hatena.ne.jp/blp1526/