Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: How to add timestamp to vmstat and iostat output  (Read 11320 times)

0 Members and 1 Guest are viewing this topic.

vinayakk

  • Guest
How to add timestamp to vmstat and iostat output
« on: February 08, 2014, 06:59:09 am »
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:

Code: [Select]
# vmstat 1 | awk '{now=strftime("%Y-%m-%d %T "); print now $0}'
2014-02-08 06:54:15 procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
2014-02-08 06:54:15  r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
2014-02-08 06:54:15  2  0  82928 122172  38016 746940    1    1    14    17   86  109 15  2 82  1
2014-02-08 06:54:16  2  0  82928 149692  38016 716668    0    0     0     0  827 1354 14  4 83  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.

 :) :)