How to use the command `dstat` (with examples)
- Linux
- December 25, 2023
dstat
is a versatile tool for generating system resource statistics. It provides detailed information about CPU, disk, network, paging, and system statistics. It can be useful for monitoring system performance and diagnosing issues.
Use case 1: Display CPU, disk, net, paging and system statistics
Code:
dstat
Motivation: This use case is helpful when you want to monitor the overall system resource usage in real-time. It provides a comprehensive view of CPU, disk, network, paging, and system statistics.
Explanation: Running dstat
without any arguments will display the default statistics, including CPU usage, disk I/O, network throughput, paging activity, and system load.
Example output:
----total-cpu-usage----
usr sys idl wai hiq siq stl
2 1 97 0 0 0 0
Use case 2: Display statistics every 5 seconds and 4 updates only
Code:
dstat 5 4
Motivation: This use case is useful when you want to collect system resource statistics at a specific interval for a limited number of updates. It allows you to capture periodic snapshots of the system’s performance.
Explanation: The command dstat 5 4
sets the update interval to 5 seconds and limits the number of updates to 4. It will display statistics every 5 seconds, and it will stop after 4 updates.
Example output:
----time---- --total-cpu-usage-- -dsk/total- -net/total- ---paging-- --system--
01-02 08:29:01 10 96 0 0 0 0| 0 7764B/s 1.4k/s| 678k 288M| 800 1008
01-02 08:29:06 6 94 0 0 0 0| 4 1742k/s 1.1k/s| 60k 95M| 1128B 800
01-02 08:29:11 7 93 0 0 0 0| 4 4212k/s 1.1k/s| 16k 40M| 6244B 872
01-02 08:29:16 6 94 0 0 0 0| 4 9504k/s 1.0k/s| 0 0 | 116k 0
Use case 3: Display CPU and memory statistics only
Code:
dstat --cpu --mem
Motivation: This use case is helpful when you want to focus on CPU and memory-related statistics. It provides information about CPU usage, interrupts, context switches, memory usage, and swap activity.
Explanation: The command dstat --cpu --mem
enables the --cpu
and --mem
options to display CPU and memory statistics only. It excludes other resource statistics like disk, network, and paging.
Example output:
---cpu-usage--- ---mem-usage--
usr sys idl wai hiq siq| used buff cach free
2 1 97 0 0 0| 4.8G 2.2M 207M 10G
Use case 4: List all available dstat plugins
Code:
dstat --list
Motivation: This use case is useful when you want to explore all the available plugins for dstat
. It gives you a list of options to customize the statistics displayed.
Explanation: The command dstat --list
lists all the plugins available for dstat
. It provides a comprehensive overview of the different statistics and information you can gather using dstat
.
Example output:
List of available plugins:
aio, cpu, cpu24, disk, disk24, disk24old, epoch, fs, int, io, ipc, load, lock, mem, net, page, page24, proc, raw, socket, swap, swapold, sys, tcp, time, udp, unix, vm, write
Use case 5: Display the process using the most memory and most CPU
Code:
dstat --top-mem --top-cpu
Motivation: This use case is helpful when you want to identify the processes consuming the most memory and CPU resources on the system. It allows you to pinpoint resource-intensive processes.
Explanation: The command dstat --top-mem --top-cpu
enables the --top-mem
and --top-cpu
options to display the process using the most memory and CPU, respectively. It provides an overview of the resource usage by individual processes.
Example output:
--top-cpu-usage-- --top-mem-usage--
usr sys idl wai hiq siq stl| used buff cach free
5 2 92 0 0 0 0| 5.0G 9.1M 213M 10G
Use case 6: Display battery percentage and remaining battery time
Code:
dstat --battery --battery-remain
Motivation: This use case is useful for monitoring the battery status on a laptop or portable device. It provides information about the battery percentage and the remaining battery time.
Explanation: The command dstat --battery --battery-remain
enables the --battery
and --battery-remain
options to display the battery percentage and the remaining battery time, respectively. It provides insights into the current battery status.
Example output:
---battery-usage-- --battery-remain-
now full dsc rc1 rc2 rc3 rc4 rc5| time
63 98 3 2 2 23 68 0| 6:40
Conclusion:
In this article, we explored several use cases of the dstat
command, a versatile tool for generating system resource statistics. It is a valuable tool for monitoring system performance, diagnosing issues, and customizing the displayed statistics based on specific requirements. Whether you need an overview of overall system resource usage or specific information about CPU, memory, plugins, processes, or battery status, dstat
provides a comprehensive set of features to meet your monitoring needs.