Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Linux dstat command

Linux dstat command

Linux Command Reference Linux Command Reference


dstat is a powerful Linux system monitoring tool that displays system resource usage in real time, including key metrics such as CPU, memory, disk, and network. dstat is designed to replace traditional tools such as vmstat, iostat, and netstat, providing a unified monitoring interface.

Main Features of dstat


dstat Basic Syntax

The basic command format of dstat is as follows:

dstat [选项] [间隔时间] [执行次数]

Common parameters

Parameters Description
-c Show CPU usage
-d Show disk read/write activity
-m Show memory usage
-n Show network status
-l Show system load
-p Show process status
-s Show swap usage
-t Show timestamps
--output Save output to a CSV file
--top-cpu Show the processes consuming the most CPU
--top-mem Show the processes consuming the most memory

Common Monitoring Scenario Examples

1. Basic System Monitoring

dstat -cdlmnpsy

This command displays:

2. Monitor Specific Resources

Example

graph TD

    A[Start monitoring] --> B{Select monitoring item}

    B -->|CPU| C[dstat -c]

    B -->|Memory| D[dstat -m]

    B -->|Disk| E[dstat -d]

    B -->|Network| F[dstat -n]

3. Monitoring with Timestamps

dstat -t -cdm

Example output:

----system---- ----total-cpu-usage---- -dsk/total- ---memory-usage----

     time     |usr sys idl wai hiq siq| read  writ| used  buff  cach  free

12-05 14:30:01|  2   1  96   0   0   1|  12k   25k| 3.2G 1.1G  5.6G  2.4G

12-05 14:30:02|  3   1  95   0   0   1|  24k   18k| 3.2G 1.1G  5.6G  2.4G

4. Save Monitoring Results to a File

dstat -cdm --output /tmp/dstat_output.csv 5 10

This command will:


Advanced usage

1. Monitor a Specific Process

dstat --top-cpu --top-mem

2. Customize Monitoring Items

dstat -c -d -n -N eth0,total

This command monitors:

3. Combine Plugins

dstat supports a variety of plugins, which can be separated by commas:

dstat --time,proc,disk,net,tcp,load,sys


Frequently Asked Questions

1. What is the difference between dstat and the top command?

Feature dstat top
Display Mode Table form List form
Monitoring Scope System-wide Mainly processes
Refresh Mode Customizable interval Fixed interval
Data export Supports CSV Not supported

2. How to install dstat?

On most Linux distributions, it can be installed via the package manager:

Example

Ubuntu/Debian

sudo

apt-get install

dstat

CentOS/RHEL

sudo

yum install

dstat

Fedora

sudo

dnf

install

dstat

3. How to interpret dstat's output?


Best Practice Recommendations

  1. Long-term Monitoring: for servers, it is recommended to use the --output parameter to save the monitoring data
  2. Problem diagnosis: when performance problems occur, use dstat -tcdmn to quickly view the usage of each resource
  3. Benchmarking: before and after system tuning, use dstat to record performance data for comparison
  4. Custom Views: create your own dstat monitoring combinations based on actual needs and save them as aliases for convenience

Summary

dstat is a powerful tool for Linux system administrators and developers; it provides comprehensive system monitoring capabilities and is highly customizable. By mastering dstat, you can:

  1. Quickly identify system performance bottlenecks
  2. Monitor usage trends of key resources
  3. Collect performance data for analysis
  4. Replace multiple single-function monitoring tools

Readers are encouraged to try different combinations of parameters in real work and find the monitoring solution best suited to their work scenarios.


Linux Command Reference Linux Command Reference