dstat command in Linux w/ examples
This dstat command guide follows my previous 90 Linux Commands frequently used by Linux Sysadmins article. As time allows, I will continue to publish articles on around the 90 commands geared toward Linux sysadmins and Linux power users. Let’s continue this series with the dstat
command.
Dstat is used for generating system resource statistics. It is a versatile replacement for vmstat, iostat, netstat and ifstat and overcomes some of the limitations of those tools. In addition, it adds some extra features, more counters and flexibility. Dstat is suitable for monitoring systems during performance tuning, benchmarking and troubleshooting.
The general syntax of the dstat
command is:
dstat [-afv] [options..] [delay [count]]
Table of Contents
dstat command in Linux
Dstat allows an overview of system resources in real-time. For example, you can compare disk utilization with interrupts or compare network bandwidth numbers directly with storage I/O.
Dstat delivers detailed selective information in columns and indicates the magnitude and units. Less confusion, fewer mistakes. Most notably, it makes it easy to create plugins to collect your counters. Dstat’s output by default is designed for being interpreted by humans in real-time; however, you can export details to CSV output to a file to be imported later into Gnumeric or Excel to generate graphs.
dstat features
- Combines vmstat, iostat, ifstat, netstat information.
- It shows stats in exactly the same timeframe.
- Enable/order counters as they make most sense during analysis/troubleshooting.
- Modular design.
- Written in python so easily extendable for the task at hand.
- Easy to extend (add your own counters).
- Can summarize grouped block/network devices and give total numbers.
- Can show interrupts per device.
- Very accurate timeframes, no timeshifts when the system is stressed.
- Shows exact units and limits conversion mistakes.
- Indicate different units with different colors.
- Show intermediate results when delay > 1.
- Allows export to CSV, which can be imported in Gnumeric and Excel to generate graphs.
dstat examples
To display CPU, disk, net, paging and system statistics (default), use:
dstat
To display statistics every 5 seconds and 4 updates only:
dstat 5 4
To display CPU and memory statistics only, use:
dstat --cpu --mem
To list all available dstat plugins, use: (see above screenshot)
dstat --list
Display the process using the most memory and most CPU:
dstat --top-mem --top-cpu
To display information in vmstat format, use:
dstat --vmstat
To display the stats of all processes, use:
dstat -a
To use dstat to relate disk-throughput with network-usage (eth0), total CPU-usage and system counters, use:
dstat -dnyc -N eth0 -C total -f 5
To check dstat’s behaviour and the system impact of dstat, use:
dstat -taf --debug
To use the time plugin together with cpu, net, disk, system, load, proc and top_cpu plugins, use: (see above screenshot)
dstat -tcndylp --top-cpu
…this is identical to using:
dstat --time --cpu --net --disk --sys --load --proc --top-cpu
To use dstat to relate advanced CPU stats with interrupts per device, use:
dstat -t --cpu-adv -yif
dstat options
-c, –cpu
enable CPU stats (system, user, idle, wait), for more CPU related stats also see –cpu-adv and –cpu-use
-C 0,3,total
include cpu0, cpu3 and total (when using -c/–cpu); use all to show all CPUs
-d, –disk
enable disk stats (read, write), for more disk related stats look into the other –disk plugins
-D total,hda
include total and hda (when using -d/–disk)
-g, –page
enable page stats (page in, page out)
-i, –int
enable interrupt stats
-I 5,10
include interrupt 5 and 10 (when using -i/–int)
-l, –load
enable load average stats (1 min, 5 mins, 15mins)
-m, –mem
enable memory stats (used, buffers, cache, free); for more memory-related stats also try –mem-adv and –swap
-n, –net
enable network stats (receive, send)
-N eth1,total
include eth1 and total (when using -n/–net)
-p, –proc
enable process stats (runnable, uninterruptible, new)
-r, –io
enable I/O request stats (read, write requests)
-s, –swap
enable swap stats (used, free)
-S swap1, total
include swap1 and total (when using -s/–swap)
-t, –time
enable time/date output
-T, –epoch
enable time counter (seconds since epoch)
-y, –sys
enable system stats (interrupts, context switches)
–aio
enable aio stats (asynchronous I/O)
–cpu-adv
enable advanced cpu stats
–cpu-use
enable only cpu usage stats
–fs, –filesystem
enable filesystem stats (open files, inodes)
–ipc
enable ipc stats (message queue, semaphores, shared memory)
–lock
enable file lock stats (posix, flock, read, write)
–mem-adv
enable advanced memory stats
–raw
enable raw stats (raw sockets)
–socket
enable socket stats (total, tcp, udp, raw, ip-fragments)
–tcp
enable tcp stats (listen, established, syn, time_wait, close)
–udp
enable udp stats (listen, active)
–unix
enable unix stats (datagram, stream, listen, active)
–vm
enable vm stats (hard pagefaults, soft pagefaults, allocated, free)
–vm-adv
enable advance vm stats (steal, scanK, scanD, pgoru, astll)
–zones
enable zoneinfo stats (d32F, d32H, normF, normH)
–plugin-name
enable (external) plugins by plugin name, see PLUGINS for options
–list
list the internal and external plugin names
-a, –all
equals -cdngy (default)
-f, –full
expand -C, -D, -I, -N and -S discovery lists
-v, –vmstat
equals -pmgdsc -D total
–bits
force bits for values expressed in bytes
–float
force float values on-screen (mutual exclusive with –integer)
–integer
force integer values on-screen (mutual exclusive with –float)
–bw, –blackonwhite
change colors for white background terminal
–nocolor
disable colors
–noheaders
disable repetitive headers
–noupdate
disable intermediate updates when delay > 1
–output file
write CSV output to file
–profile
show profiling statistics when exiting dstat
dstat plugins
While anyone can create additional dstat plugins, dstat ships with several default plugins. These are:
–battery
battery in percentage (needs ACPI)
–battery-remain
battery remaining in hours, minutes (needs ACPI)
–cpufreq
CPU frequency in percentage (needs ACPI)
–dbus
number of dbus connections (needs python-dbus)
–disk-avgqu
average queue length of the requests that were issued to the device
–disk-avgrq
average size (in sectors) of the requests that were issued to the device
–disk-svctm
average service time (in milliseconds) for I/O requests that were issued to the device
–disk-tps
number of transfers per second that were issued to the device
–disk-util
percentage of CPU time during which I/O requests were issued to the device (bandwidth utilization for the device)
–disk-wait
average time (in milliseconds) for I/O requests issued to the device to be served
–dstat
show dstat cputime consumption and latency
–dstat-cpu
show dstat advanced CPU usage
–dstat-ctxt
show dstat context switches
–dstat-mem
show dstat advanced memory usage
–fan
fan speed (needs ACPI)
–freespace
per filesystem disk usage
–gpfs
GPFS read/write I/O (needs mmpmon)
–gpfs-ops
GPFS filesystem operations (needs mmpmon)
–helloworld
Hello world example dstat plugin
–innodb-buffer
show innodb buffer stats
–innodb-io
show innodb I/O stats
–innodb-ops
show InnoDB operations counters
–lustre
show lustre I/O throughput
–md-status
show software raid (md) progress and speed
–memcache-hits
show the number of hits and misses from Memcache
–mysql-io
show the MySQL I/O stats
–mysql-keys
show the MySQL keys stats
–net-packets
show the number of packets received and transmitted
–nfs3
show NFS v3 client operations
–nfs3-ops
show extended NFS v3 client operations
–nfsd3
show NFS v3 server operations
–nfsd3-ops
show extended NFS v3 server operations
–nfsd4-ops
show extended NFS v4 server operations
–nfsstat4
show NFS v4 stats
–ntp
show NTP time from an NTP server
–postfix
show postfix queue sizes (needs postfix)
–power
show power usage
–proc-count
show total number of processes
–qmail
show qmail queue sizes (needs qmail)
–redis
show redis stats
–rpc
show RPC client calls stats
–rpcd
show RPC server calls stats
–sendmail
show sendmail queue size (needs sendmail)
–snmp-cpu
show CPU stats using SNMP from DSTAT_SNMPSERVER
–snmp-load
show load stats using SNMP from DSTAT_SNMPSERVER
–snmp-mem
show memory stats using SNMP from DSTAT_SNMPSERVER
–snmp-net
show network stats using SNMP from DSTAT_SNMPSERVER
–snmp-net-err
show network errors using SNMP from DSTAT_SNMPSERVER
–snmp-sys
show system stats (interrupts and context switches) using SNMP from DSTAT_SNMPSERVER
–snooze
show number of ticks per second
–squid
show squid usage statistics
–test
show test plugin output
–thermal
system temperature sensors
–top-bio
show most expensive block I/O process
–top-bio-adv
show most expensive block I/O process (incl. pid and other stats)
–top-childwait
show process waiting for child the most
–top-cpu
show most expensive CPU process
–top-cpu-adv
show most expensive CPU process (incl. pid and other stats)
–top-cputime
show process using the most CPU time (in ms)
–top-cputime-avg
show process with the highest average timeslice (in ms)
–top-int
show most frequent interrupt
–top-io
show most expensive I/O process
–top-io-adv
show most expensive I/O process (incl. pid and other stats)
–top-latency
show process with highest total latency (in ms)
–top-latency-avg
show process with the highest average latency (in ms)
–top-mem
show process using the most memory
–top-oom
show process that will be killed by OOM the first
–utmp
show number of utmp connections (needs python-utmp)
–vm-cpu
show VMware CPU stats from hypervisor
–vm-mem
show VMware memory stats from hypervisor
–vm-mem-adv
show advanced VMware memory stats from hypervisor
–vmk-hba
show VMware ESX kernel vmhba stats
–vmk-int
show VMware ESX kernel interrupt stats
–vmk-nic
show VMware ESX kernel port stats
–vz-cpu
show CPU usage per OpenVZ guest
–vz-io
show I/O usage per OpenVZ guest
–vz-ubc
show OpenVZ user beancounters
–wifi
wireless link quality and signal to noise ratio
–zfs-arc
show ZFS arc stats
–zfs-l2arc
show ZFS l2arc stats
–zfs-zil
show ZFS zil stats
Without plugins, possible internal stats are
aio, cpu, cpu24, cpu-adv, cpu-use, disk, disk24, disk24-old, epoch, fs, int, int24, io, ipc, load, lock, mem, mem-adv, net, page, page24, proc, raw, socket, swap, swap-old, sys, tcp, time, udp, unix, vm, vm-adv, zones
Useful links/references:
- Dstat: pluginbased realtime monitoring (PDF file)
- dool – Python3 compatible clone of dstat.
- dstat is now maintained by Red Hat.
Related commands:
top
– shows an overall system view.btop
– very functional and fancy top/htop alternativevmstat
– shows system memory, processes, interrupts, paging, block I/O, and CPU info.sysstat
– Performance monitoring tools for Linux.
Conclusion
In wrapping up this exploration of the dstat command, it’s clear that its utility extends far beyond simple system monitoring. Dstat offers Linux sysadmins and power users a dynamic and detailed window into their systems’ performance. With its extensive plugin architecture and ability to present complex data in an accessible format, dstat is a critical tool for anyone serious about performance tuning, benchmarking, or troubleshooting Linux systems.
As this series progresses, integrating dstat into your diagnostic toolkit can significantly enhance your ability to maintain and optimize your computing environment efficiently.