Measuring Linux System Performance with dstat February 16, 2011Posted by Tournas Dimitrios in Linux admin tools.
dstat is a sort of general-purpose system profiling tool, but it’s CLI-based. It covers all the bases: it’s usable to log data or view it in real time; it can show CPU load, disk I/O, network receive/send, etc. It also produces colorized output at the console, which makes it somewhat easier to scan results quickly.
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.
Dstat is written by Dag Wieers. Unlike some of the performance tools, it includes a decent amount of documentation. And it’s extensible; plugins can be added to Dstat with Python. If you want to analyze your data later, you can use the –output option to write the information to a CSV file suitable for import into OpenOffice.org, Gnumeric, or whatever your favorite spreadsheet might be. CSV is an asci plain text format , scripting languages like PHP , Bash etc.. can parse it’s content .
The most recent version of dstat ships with quite a few plugins that are suitable for servers and personal systems. This includes plugins to examine MySQL performance, Postfix, Sendmail, Qmail, and much more. You can combine the plugins with built-in functions of dstat as well. So, for instance, if you want to watch MySQL I/O along with the -a (all) option, you can use dstat –mysql-io -a. Some experimentation may be required and not all options can be combined with other options.
According to the official documentation ( /usr/share/doc/dstat-0.6.6/performance.txt)
“” Depending on the stats being used and the load on the server itself the impact of dstat has on the system you are monitoring micht be considerable . “”
Let see some practical examples :
|dstat [-afv] [-cdgilmnpsty] [-D..] [-I..] [-N..] [delay [count]]|
|dstat||If you want to use dstat just use the following command|
||Checking dstat’s behaviour and the system’s impact on dstat|
|dstat -tcndylp -M topcpu||Using the time plugin together with cpu, net, disk, system, load, proc and topcpu pluginsthis is identical to:
dstat -M time,cpu,net,disk,sys,load,proc,topcpu
|dstat -tcyif||Using dstat to relate cpu stats with interrupts per device:|
|dstat -dnyc -N eth0 -C total -f 5||Using dstat to relate disk-throughput with network-usage (eth0), total CPU-usage and system counters:|
|dstat –output stat.csv||write CSV output to file|
Get a Report by Mail :
There may be cases wherein you want to observe how your server is performing over a period of time. You can setup a background process in Linux that will give you a reading with a certain interval, generate a report, and mail out the file to you. This can be especially useful during a stress-test. Here’s how you could do that. The following script will run Dstat for three hours, reading the data every 30 seconds, and will mail out the report to email@example.com.
dstat –output /tmp/dstat_data_mail.csv -CDN 30 360
mutt -a /tmp/dstat_data_mail.csv -s “Dstat Report for 3 hour run” firstname.lastname@example.org < /dev/null
Save the above script in a file called dstat_script.sh on your server, give it executable permission and then run it as a background process:
# chmod +x dstat_script.sh
# nohup ./dstat_script.sh &
Done. Yes, it’s that simple. You will now be mailed this report after it’s done running. You can optionally schedule this script as a daily cron job so that you can receive this data every day.
As you may already have realized Dstat is a wonderful tool when applied to performance monitoring and debugging. The granularity, frequency, and nature of the data collected are completely up to you. Dstat empowers you to know what is going on on your server. Used wisely this power can result in a lot less sleepless nights for you.