Recently, started fiddling around with how to monitor and graph performance data on linux boxes. Other than the usual tools like top and vmstat, which are either interactive (top) or too textual to do anything much.
First off, vmstat, doesnt lend itself well to graphing without additional scripts to lay out the data so tools like gnuplot can be used. Secondly, and more seriously, it doesn’t include a timestamp in the output.
Looking around a bit found that dstat seems to be a good replacement to vmstat (and iostat) – and the generated data is consumable with gnuplot.
Here’s a quick example of generating graphs for CPU user, system and idle times
dstat -tc 5 500 > dstat.raw
now fire up gnuplot and go ahead and plot it
gnuplot> set xdata time gnuplot> set timefmt "%s" gnuplot> set format x "%M:%S" gnuplot> plot "dstat.raw" using 1:2 title "User" with lines, "dstat.raw" using 1:3 title "Sys" with lines, "dstat.raw" using 1:4 title "Idle" using lines
To make gnuplot generat an output file, you need
gnuplot> set term png
gnuplot> set output “dstat.png”
gnuplot> replot
And you’re done. here’s the graph generated on my machine. There’s loads more that you can do – and admittedly, you can do everything by dumping your file to excel. However, that doesn’t lend itself well to a completely automated process. When you’re doing performance testing and such like, you will likely repeat this enough number of times. Not having to do it manually helps big time!
Hi,
very nice example! Unfortunately one important line is cutted. Here is a shell script which creates the plot on dstat.raw (i deleted the header in dstat.raw):
#!/usr/bin/gnuplot -persist
set xdata time
set timefmt "%d-%m %H:%M:%S"
set format x "%H:%M"
set yrange [0:100]
set grid
set title "dstat CPU Usage"
set xlabel "time"
set ylabel "total-cpu-usage"
#-----time----- ----total-cpu-usage----
# date/time |usr sys idl wai hiq siq
#13-06 01:18:14| 5 1 93 1 0 0
plot "dstat.raw" using 1:3 w lp t "user [%]", \
"" u 1:4 w lp t "system [%]", \
"" u 1:5 w lp t "idle [%]", \
"" u 1:6 w lp t "wait [%]"
greetings
Florian
Very neat. Out of curiosity, any idea how to make gnuplot convert the memory from bytes to megabytes or something? Suppose I could awk/perl/python the values be I’d rather just leave the data in its original format in the file and just convert on the graphing call itself.
Eg, if you run this:
dstat -tm -o memory.csv, you would get this:
$ cat memory.csv
“Dstat 0.6.7 CSV output”
“Author:”,”Dag Wieers “,,,,”URL:”,”http://dag.wieers.com/home-made/dstat/”
“Host:”,”fooHost”,,,,”User:”,”bilsch”
“Cmdline:”,”dstat -tm -o memory.csv”,,,,”Date:”,”15 Dec 2008 15:22:13 EST”
“time”,”memory usage”,,,
“date/time”,”used”,”buff”,”cach”,”free”
15-12 15:22:13,10640392192.0,753188864.0,21301972992.0,999010304.0
15-12 15:22:14,10640392192.0,753188864.0,21301972992.0,999010304.0
15-12 15:22:15,10640392192.0,753188864.0,21301972992.0,999010304.0
15-12 15:22:16,10640384000.0,753188864.0,21301972992.0,999018496.0
sed -i -e ‘1,7s/^/# /’ -e ‘7,$s/,/ /g’ yields
# “Dstat 0.6.7 CSV output”
# “Author:”,”Dag Wieers “,,,,”URL:”,”http://dag.wieers.com/home-made/dstat/”
# “Host:”,”fooHost”,,,,”User:”,”bilsch”
# “Cmdline:”,”dstat -tm -o memory.csv”,,,,”Date:”,”15 Dec 2008 15:22:13 EST”
#
# “time”,”memory usage”,,,
# “date/time” “used” “buff” “cach” “free”
15-12 15:22:13 10640392192.0 753188864.0 21301972992.0 999010304.0
15-12 15:22:14 10640392192.0 753188864.0 21301972992.0 999010304.0
15-12 15:22:15 10640392192.0 753188864.0 21301972992.0 999010304.0
15-12 15:22:16 10640384000.0 753188864.0 21301972992.0 999018496.0
( eg, make gnuplot ignore the output junk )
reset
set xlabel “time”
set key outside bottom
set ylabel “%”
set autoscale
set grid
set xdata time
set format x “%H:%M”
set timefmt “%d-%m %H:%M:%S”
set ylabel “bytes”
set title “physical memory”
plot “memory.csv” using 1:3 title “used” with lines, \
“memory.csv” using 1:4 title “buffered” with lines, \
“memory.csv” using 1:5 title “cached” with lines
Another alternative is to use Vmstax.
Have a look at :
http://www.michenux.net/dstat-graph-using-vmstax-154.html