Some of the popular and frequently used system resource generating tools available on the Linux platform include vmstat, netstat, iostat, ifstat and mpstat. They are used for reporting statistics from different system components such as virtual memory, network connections and interfaces, CPU, input/output devices and more.
As a system administrator, you may be looking for that one tool that can give your a good amount of the information provided by above tools, even more, a single and powerful tool that has additional features and capabilities, then look no further than
dstat is a powerful, flexible and versatile tool for generating Linux system resource statistics, that is a replacement for all the tools mentioned above. It comes with extra features, counters and it is highly extensible, users with Python knowledge can build their own plugins.
Features of dstat:
- Joins information from vmstat, netstat, iostat, ifstat and mpstat tools
- Displays statistics simultaneously
- Orders counters and highly-extensible
- Supports summarizing of grouped block/network devices
- Displays interrupts per device
- Works on accurate timeframes, no timeshifts when a system is stressed
- Supports colored output, it indicates different units in different colors
- Shows exact units and limits conversion mistakes as much as possible
- Supports exporting of CSV output to Gnumeric and Excel documents
How to Install dstat in Linux Systems
dstat is available to install from default repositories on most Linux distributions, you can install and use it for monitoring a Linux system in the process of performance tuning tests or troubleshooting exercises.
# yum install dstat [On RedHat/CentOS and Fedora] $ sudo apt-get install dstat [On Debian, Ubuntu and Linux Mint]
It works in real-time, outputting selective information in columns, including the magnitude and units for stats displayed after every one second, by default.
Note: The dstat output is aimed specifically for human interpretation, not as input for other tools to process.
Below is an output seen after running the dstat command without any options and arguments (similar to using
-cdngy (default) options or
The output above indicates:
- CPU stats: cpu usage by a user (usr) processes, system (sys) processes, as well as the number of idle (idl) and waiting (wai) processes, hard interrupt (hiq) and soft interrupt (siq).
- Disk stats: total number of read (read) and write (writ) operations on disks.
- Network stats: total amount of bytes received (recv) and sent (send) on network interfaces.
- Paging stats: number of times information is copied into (in) and moved out (out) of memory.
- System stats: number of interrupts (int) and context switches (csw).
To display information provided by
vmstat, use the
$ dstat --vmstat
In the image above, dstat displays:
- Process stats: number of running (run), blocked (blk) and new (new) spawned processes.
- Memory stats: amount of used (used), buffered (buff), cached (cach) and free (free) memory.
I already explained at the last three sections (paging, disk and system stats) in the previous example.
Let us dive into some advanced dstat system monitoring commands. In the next example, we want to monitor a single program that is using the most CPU and consuming the most amount of memory.
The options in the command are:
-c– cpu usage
--top-cpu– process using most CPU
-dn– disk and network stats
--top-mem– process consuming the most memory
$ dstat -c --top-cpu -dn --top-mem
Additionally, you can also store the output of dstat in a
.csv file for analysis at a latter time by enabling the
--output option as in the example below.
0Here, we are displaying the time, cpu, mem, system load stats with a one second delay between 5 updates (counts).
$ dstat --time --cpu --mem --load --output report.csv 1 5
There are several internal (such as options used in previous example) and external dstat plugins you can use with dstat, to view a list of all available plugins, run the command below:
$ dstat --list
It reads plugins from the paths below, therefore, add external plugins in these directories:
~/.dstat/ (path of binary)/plugins/ /usr/share/dstat/ /usr/local/share/dstat/
dstat is a versatile, all-in-one system resources statistics generating tool, it combines information from several other tools such as vmstat, mpstat, iostat, netstat and ifstat.
I hope this review will be helpful to you, most importantly, you can share with us any suggestions, supplementary ideas to improve the article and also give us feedback about your experience using of dstat through the comment section below.