Showing posts with label vmstat. Show all posts
Showing posts with label vmstat. Show all posts

Wednesday, June 26, 2013

How to add timestamp to vmstat and iostat output

vmstat does not have an option to log timestamps which may cause its logs to be difficult to interpret later.
The workaround is to use awk to generate timestamp and print vmstat output plus data:
# vmstat 1 | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'
2013-06-26 21:47:41 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
2013-06-26 21:47:41  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
2013-06-26 21:47:41  1  0      0 385944  71768 517152    0    0    96    28 1018  118  3  5 89  3  0
2013-06-26 21:47:42  0  0      0 385944  71768 517152    0    0     0     0 1008   65  0  1 99  0  0

2013-06-26 21:47:43  0  0      0 385944  71768 517152    0    0     0     0 1023   73  0  0 100  0  0

Fortunately iostat on Linux have -t switch which adds timestamp for every output.
However if you're using iostat on system where -t switch is not available you may use the same trick we did with vmstat.