Linux dstat Command

Linux 命令大全Linux Command Encyclopedia


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

Main features of dstat

  • Multi-functional integration: Integrates the functions of multiple system monitoring tools
  • Real-time display: Can continuously refresh and display system status
  • Customizability: Allows users to select specific metrics to monitor
  • Color output: Uses color display by default for easy identification of abnormal values
  • CSV export: Supports exporting monitoring data to CSV format

dstat Basic Syntax

The basic command format of dstat is as follows:

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

Common parameter description

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

Common monitoring scenario examples

1. Basic system monitoring

dstat -cdlmnpsy

This command will display:

  • CPU usage
  • Disk read/write
  • System load
  • Memory usage
  • Network status
  • Process status
  • Swap partition usage

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

Output example:

----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:

  • Monitor CPU, disk, and memory
  • Refresh every 5 seconds
  • Execute a total of 10 times
  • Save the results to /tmp/dstat_output.csv

Advanced usage

1. Monitor a specific process

dstat --top-cpu --top-mem

2. Custom monitoring items

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

This command will monitor:

  • CPU usage
  • Disk activity
  • Network traffic (specific network interface eth0 and total)

3. Combine plugins

dstat supports multiple plugins, which can be separated by commas:

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

FAQ

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

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

2. How to install dstat?

On most Linux distributions, you can install it 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 output?

  • CPU section: usr (user space), sys (system space), idl (idle), wai (I/O wait)
  • Memory section: used (used), buff (buffer), cach (cache), free (free)
  • Disk section: read (read), writ (write), usually in KB/s

Best practice recommendations

  1. Long-term monitoring: For servers, it is recommended to use--outputparameter to save monitoring data
  2. Problem diagnosis: When performance issues occur, usedstat -tcdmnto quickly view resource usage
  3. Benchmark testing: Before and after system tuning, use dstat to record performance data for comparison
  4. Custom view: Create your own dstat monitoring combination according to actual needs, and save it as an alias 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 key resource usage trends
  3. Collect performance data for analysis
  4. Replace multiple single-function monitoring tools

It is recommended that readers try different parameter combinations in actual work to find the monitoring solution that best suits their work scenario.


Linux 命令大全Linux Command Encyclopedia

Other extensions