Linux常用命令-dstat

命令

dstat

描述

versatile tool for generating system resource statistics
查看系统资源信息

用法

1
dstat [-afv] [options..] [delay [count]]

选项

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
Options:
-c, --cpu 显示CPU状态(system, user, idle, wait, hardware interrupt, software interrupt)
-C 0,1,total 显示多核CPU状态,如显示cpu0, cpu1 and total状态,需要配合-c选项一起使用
-d, --disk 显示磁盘状态
-D sda,total 显示多块磁盘状态,需要配合-d选项一起使用
-g, --page enable page stats
-i, --int enable interrupt stats
-I 5,eth2 include int5 and interrupt used by eth2
-l, --load 显示系统负载
-m, --mem 显示内存状态
-n, --net 显示网络状态
-N eth1,total 显示指定网卡状态
-p, --proc 显示进程状态
-r, --io enable io stats (I/O requests completed)
-s, --swap 显示swap状态
-S swap1,total include swap1 and total
-t, --time enable time/date output
-T, --epoch enable time counter (seconds since epoch)
-y, --sys enable system stats

--aio enable aio stats
--fs, --filesystem enable fs stats
--ipc enable ipc stats
--lock enable lock stats
--raw enable raw stats
--socket enable socket stats
--tcp enable tcp stats
--udp enable udp stats
--unix enable unix stats
--vm enable vm stats

--plugin-name enable plugins by plugin name (see manual)
--list 显示所有可用插件

-a, --all equals -cdngy (default)
-f, --full automatically expand -C, -D, -I, -N and -S lists
-v, --vmstat equals -pmgdsc -D total

--bits force bits for values expressed in bytes
--float force float values on screen
--integer force integer values on screen

--bw, --blackonwhite change colors for white background terminal
--nocolor disable colors (implies --noupdate)
--noheaders disable repetitive headers
--noupdate disable intermediate updates
--output file write CSV output to file
--profile show profiling statistics when exiting dstat

delay is the delay in seconds between each update (default: 1)
count is the number of updates to display before exiting (default: unlimited)

PLUGINS
--top-bio show most expensive block I/O process
--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-io show most expensive I/O process
--top-io-adv show most expensive I/O process (incl. pid and other stats)
--top-mem show process using the most memory

注意

如果不指定[delay [count]]参数,默认每秒更新一次数据,并一直显示

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
$ dstat --version
Dstat 0.7.2

# 命令为python脚本
$ ll /usr/bin/dstat
-rwxr-xr-x 1 root root 88184 Jun 10 2014 /usr/bin/dstat
# 插件目录/usr/share/dstat
$ ll /usr/share/dstat/dstat.py
-rwxr-xr-x 1 root root 88184 Jun 10 2014 /usr/share/dstat/dstat.py

$ dstat -c
----total-cpu-usage----
usr sys idl wai hiq siq
0 0 100 0 0 0
0 0 100 0 0 0

$ dstat -cC 0,1,total
-------cpu0-usage--------------cpu1-usage-----------total-cpu-usage----
usr sys idl wai hiq siq:usr sys idl wai hiq siq:usr sys idl wai hiq siq
0 0 100 0 0 0: 0 0 100 0 0 0: 0 0 100 0 0 0
0 0 100 0 0 0: 0 0 100 0 0 0: 0 0 100 0 0 0

$ dstat -dD sda,sdb,total
--dsk/sda-----dsk/sdb----dsk/total-
read writ: read writ: read writ
19k 3487B: 56B 1B: 19k 3488B
0 0 : 0 0 : 0 0
0 56k: 0 0 : 0 56

$ dstat -l
---load-avg---
1m 5m 15m
0 0.01 0.05
0 0.01 0.05

$ dstat -m
------memory-usage-----
used buff cach free
316M 63.0M 1520M 81.6M

$ dstat -nN eth0,total
--net/eth0---net/total-
recv send: recv send
0 0 : 0 0
1586B 106B:1586B 106B

$ dstat --tcp --udp
----tcp-sockets---- --udp--
lis act syn tim clo|lis act
1 2 0 0 0| 2 0
1 2 0 0 0| 2 0

$ dstat -c -m -n 3 2
----total-cpu-usage---- ------memory-usage----- -net/total-
usr sys idl wai hiq siq| used buff cach free| recv send
0 0 100 0 0 0| 316M 64.0M 1520M 80.4M| 0 0
0 0 100 0 0 0| 316M 64.0M 1520M 80.4M| 60B 114B
0 0 100 0 0 0| 316M 64.0M 1520M 80.3M| 60B 93B
# 使用top-bio插件
$ dstat --top-bio
----most-expensive----
block i/o process
systemd 18k 944B

$ dstat --top-bio-adv
----most-expensive-block-i/o-process----
process pid read write cpu
systemd 1 18k 944B0.0%
# 显示内存占用最多的进程
$ dstat --top-mem
--most-expensive-
memory process
python2 32.0M
python2 32.0M
# 显示cpu占用最高的进程
$ dstat --top-cpu
-most-expensive-
cpu process
rsyslogd 0.5

$ dstat -dnyc -N eth0 -C total -f 5
--dsk/sda-----dsk/sdb-- --net/eth0- ---system-- ----total-cpu-usage----
read writ: read writ| recv send| int csw |usr sys idl wai hiq siq
18k 3489B: 54B 1B| 0 0 | 63 72 | 0 0 100 0 0 0
0 1638B: 0 0 | 60B 127B| 40 57 | 0 0 100 0 0 0