Dstat, an Excellent Replacement for Vmstat

For a long time, I was not satisfied with vmstat, because it does not generate timestamps. Then I came across a cool program named Dstat yesterday, which can be an excellent replacement for vmstat.

A screenshot of Dstat

A screenshot of Dstat

By using Dstat, now not only all my needs can be met but also it is pretty easy to do resource usage analysis and graphing.

As the author described, “Dstat is a versatile replacement for vmstat, iostat, netstat, nfsstat and ifstat. Dstat overcomes some of their limitations and adds some extra features, more counters and flexibility. Dstat is handy for monitoring systems during performance tuning tests, benchmarks or troubleshooting.” So why use three or more tools when one tool can give you everything you need?

Here is an example showing how to use it.

First, capture the resource usage information (CPU and memory) to a file, e.g. stat.dat:

$ dstat -tcmn > stat.dat

Then use the scripts below to create CPU and memory usage graphs:

#!/usr/bin/gnuplot
 
set terminal png
set output "cpu.png"
set title "CPU usage"
set xlabel "time"
set ylabel "percent"
set xdata time
set timefmt "%d-%m %H:%M:%S"
set format x "%H:%M"
plot "stat.dat" using 1:4 title "system" with lines, 
"stat.dat" using 1:3 title "user" with lines, 
"stat.dat" using 1:5 title "idle" with lines
#!/usr/bin/gnuplot
 
set terminal png
set output "memory.png"
set title "memory usage"
set xlabel "time"
set ylabel "size(M Bytes)"
set xdata time
set timefmt "%d-%m %H:%M:%S"
set format x "%H:%M"
plot "stat.dat" using 1:9 title "used" with lines, 
"stat.dat" using 1:10 title "buff" with lines, 
"stat.dat" using 1:11 title "cach" with lines, 
"stat.dat" using 1:12 title "free" with lines

Resource usage graph examples:
cpu

memory

Download the scripts.
http://www.zhuzhaoyuan.com/download/dstat/cpu.sh
http://www.zhuzhaoyuan.com/download/dstat/memory.sh

7 Comments »

  1. Arbow said,

    March 17, 2009 @ 11:01 pm

    great! I love it

  2. Tank said,

    March 18, 2009 @ 12:17 am

    可以去了解下Windows Management Instrumentation,你也许看到过MOM(http://www.microsoft.com/systemcenter/operationsmanager/)的广告,吹得牛逼得不得了,建议去玩玩,给咱普及普及。
    一个Linuxer可以憎恨m$,但不得不学m$的产品技术

  3. Tank said,

    March 19, 2009 @ 12:19 am

    “不能不”instead of“不得不”

  4. Michenux said,

    April 15, 2011 @ 7:58 pm

    Here is another way to generate graphs from dstat log files :

    http://www.michenux.net/dstat-graph-using-vmstax-154.html

  5. René Romero Benavides said,

    May 9, 2011 @ 11:17 pm

    Great share, thanks a lot Joshua!

  6. ramesh said,

    October 12, 2011 @ 1:55 am

    Hi,
    I just tried the scripts with gnuplot4.4patch 2, its throwing
    —-system—- —-total-cpu-usage—- ——memory-usage—– -net/total…
    stat.dat:1: illegal day of month

    btw, I hace created stat.dat using
    dstat -tcmn > stat.dat

    Any idea about this exception?

  7. Joshua said,

    October 12, 2011 @ 11:10 am

    @ramesh, oh I forgot to mention that you should delete the first line of the output of dstat, i.e. the headers of the columns.

RSS feed for comments on this post · TrackBack URI

Leave a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word