Tuesday, May 15, 2007

Timestamp your monitoring output

Some of the system / application monitoring commands (eg, vmstat, mpstat, iostat, ...) allow user to continuously monitor based on certain time interval. However, they do not have option to 'timestamp' the sampled data.

I used to do that with Tcl with 'fileevent readable' to trap the output and prepend the 'clock format.

It is possible to do all these with nawk (You cannot use awk in Solaris because it does not support "system" execution).

Run this and have the result append to the log file

vmstat 1 | nawk '{system("date +%Y-%m-%dT%H:%M:%S|tr -d \"\n\"");printf(" = %s\n",$0)}' | tee -a vmstat.log
and you will get this
2007-05-11T13:46:01 =  kthr      memory            page            disk          faults      cpu
2007-05-11T13:46:01 =  r b w   swap  free  re  mf pi po fr de sr f0 m1 m1 m1   in   sy   cs us sy id
2007-05-11T13:46:01 =  0 0 0 474432 58664   0   2  2  1  1  0  0  0  0 0  0  418   51  115  0  1 99
2007-05-11T13:46:02 =  0 0 0 318976  9368  68 600 150 0  0  0  0  0  8 0  2  481 1050  273  3  9 88
2007-05-11T13:46:03 =  0 0 0 318976  9368  24 190 40  0  0  0  0  0  2 0  0  437  438  207  1  5 94
2007-05-11T13:46:04 =  0 0 0 318976  9368  25 188 31  0  0  0  0  0  2 0  1  427  408  222  2  4 94

With the timestamp, you are able to plot it with Gnuplot with x-axis configured as time scale. Suppose we want to plot the kernal threads of runable and blocked.

set title 'Kthr - r and b'
set ylabel 'No. of Kernel Threads'
set xdata time
set timefmt '%Y-%m-%dT%H:%M:%S'
plot 'vmstat.log' using 1:3 title 'kthr-r' with linespoints, \
                  using 1:3 title 'kthr-b' with linespoints

Happy timestamp-ing :-)

Labels: ,

1 Comments:

Blogger Mr. G said...

Your last post has no comments so I am leaving one here.

I use http://feed43.com/ to generate feeds for sites that have no feeds.

But it's annoying when they change their html templates then the feed just breaks.

BTW I am at Platform now.

4:41 PM  

Post a Comment

<< Home