使用Dstat来进行Linux综合性能诊断

性能测试、评估和优化一直是系统管理维护人员工作的重点。当我们针对一台生产应用进行分析的时候,获取如CPU、内存、IO、网络吞吐和进程负载的基础数据,对于后续的性能评测和优化是至关重要的。

Linux作为目前应用最广泛的服务器操作系统,为了应对各种性能问题,已经发展出很多原生的性能检测工具。从top、vmstat、iostat到mpstat,已经可以对操作系统主要性能方面进行详细的分析。

面对越来越复杂的分析情况,我们在实践中往往需要那种全局综合性的性能工具。在一个工具里面,将所有的数据收集展现在一起。本篇主要介绍一下基于开源架构的dstat性能分析工具。

1、Dstat下载与安装

Dstat是一个自由开放团体开发的开源软件,可以从作者网站上下载到,网址为:http://dag.wiee.rs/home-made/dstat/。

根据不同的操作系统版本,Dstat提供了不同版本的安装RPM或者其他格式安装包。笔者系统为红帽6.5,所以选择适合版本进行安装。

[root@xxx-MIGPC-DB uploads]# uname -a

Linux xxx-MIGPC-DB 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

[root@xxx-MIGPC-DB uploads]# ls -l

total 164

-rw-r–r– 1 root root 164276 Dec 3 09:25 dstat-0.7.2-1.el6.rfx.noarch.rpm

安装Dstat及其简单,借助rpm工具可以直接安装。

[root@xxx-MIGPC-DB uploads]# rpm -ivh dstat-0.7.2-1.el6.rfx.noarch.rpm

warning: dstat-0.7.2-1.el6.rfx.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 6b8d79e6: NOKEY

Preparing… ########################################### [100%]

1:dstat ########################################### [100%]

[root@xxx-MIGPC-DB uploads]# rpm -qa | grep dstat

dstat-0.7.2-1.el6.rfx.noarch

2、Dstat使用方法

从官方途径上,我们可以找到正式的dstat的html格式说明文档。在实际中,我们可以通过help参数来显示功能参数。

[root@xxx-MIGPC-DB uploads]# dstat –help

Usage: dstat [-afv] [options..] [delay [count]]

Versatile tool for generating system resource statistics

Dstat options:

-c, –cpu enable cpu stats

-C 0,3,total include cpu0, cpu3 and total

-d, –disk enable disk stats

-D total,hda include hda and total

-g, –page enable page stats

-i, –int enable interrupt stats

-I 5,eth2 include int5 and interrupt used by eth2

-l, –load enable load stats

-m, –mem enable memory stats

-n, –net enable network stats

-N eth1,total include eth1 and total

-p, –proc enable process stats

-r, –io enable io stats (I/O requests completed)

-s, –swap enable swap stats

-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 list all available plugins

-a, –all equals -cdngy (default)

-f, –full automatically expand -C, -D, -I, -N and -S lists

-v, –vmstat equals -pmgdsc -D total

–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

delay is the delay in seconds between each update (default: 1)

count is the number of updates to display before exiting (default: unlimited)

从参数类型上,我们可以看到Dstat对于操作系统的监控支持是比较全面的,包括CPU、内存、磁盘和网络等多个方面。针对不同的监控需要,用户只需要输入不同的控制参数,就可以在一个结果集合中进行持续性监控。

默认情况下,Dstat监控行为如下:

[root@xxx-MIGPC-DB uploads]# dstat

You did not select any stats, using -cdngy by default.

—-total-cpu-usage—- -dsk/total- -net/total- —paging– —system–

usr sys idl wai hiq siq| read writ| recv send| in out | int csw

1 0 98 0 0 0|1395B 41k| 0 0 | 0 11B| 410 2134

25 0 75 0 0 0| 0 0 | 60B 378B| 0 0 |2058 2057

25 0 75 0 0 0| 0 32k| 401B 635B| 0 0 |2112 2128

26 0 75 0 0 0| 0 0 | 60B 170B| 0 0 |2075 2067

25 1 75 0 0 0| 0 0 | 303B 170B| 0 0 |2069 2091

25 0 75 0 0 0| 0 64k| 120B 170B| 0 0 |2042 2052

25 0 75 0 0 0| 0 0 | 60B 170B| 0 0 |2121 2102

25 0 75 0 0 0| 0 0 | 60B 170B| 0 0 |2055 2075

25 1 74 0 0 0| 0 32k| 120B 170B| 0 0 |2091 2094

默认情况下,采用cdngy参数,监控CPU、磁盘、网络、内存分页和系统统计量。

如果需要单项监控,只需要输入单个参数即可。

[root@xxx-MIGPC-DB dev]# dstat -c

—-total-cpu-usage—-

usr sys idl wai hiq siq

1 0 98 0 0 0

16 1 83 0 0 0

16 1 83 0 0 0

17 2 78 4 0 0

16 1 83 0 0 0

如果需要显示时间,可以通过-t参数来指定。

[root@xxx-MIGPC-DB dev]# dstat -a -t

—-total-cpu-usage—- -dsk/total- -net/total- —paging– —system– —-system—-

usr sys idl wai hiq siq| read writ| recv send| in out | int csw | time

1 0 98 0 0 0|1403B 41k| 0 0 | 0 11B| 410 2134 |03-12 10:18:34

16 1 80 3 0 0| 0 2280k| 53k 99k| 0 0 |2855 3135 |03-12 10:18:35

16 1 83 0 0 0| 0 32k| 53k 100k| 0 0 |2539 2842 |03-12 10:18:36

16 1 83 0 0 0| 0 0 | 53k 98k| 0 0 |2504 2799 |03-12 10:18:37

默认情况是每秒钟收集一次,如果希望和vmstat类似指定时间间隔和采样数量,可以直接在后面输入参数。

[root@xxx-MIGPC-DB dev]# dstat -at 3 10

—-total-cpu-usage—- -dsk/total- -net/total- —paging– —system– —-system—-

usr sys idl wai hiq siq| read writ| recv send| in out | int csw | time

1 0 98 0 0 0|1404B 41k| 0 0 | 0 11B| 410 2134 |03-12 10:24:42

16 1 83 0 0 0| 0 11k| 54k 97k| 0 0 |2513 2828 |03-12 10:24:45

17 1 83 0 0 0| 0 19k| 53k 96k| 0 0 |2493 2807 |03-12 10:24:48

17 1 82 0 0 0| 0 16k| 47k 93k| 0 0 |2460 2727 |03-12 10:24:51

17 1 82 0 0 0| 0 17k| 45k 92k| 0 0 |2423 2683 |03-12 10:24:54

从经验看,推荐使用的一种参数是-cdlmnpsy,可以比较充分的显示系统全貌。

[root@xxx-MIGPC-DB dev]# dstat -cdlmnpsy

—-total-cpu-usage—- -dsk/total- —load-avg— ——memory-usage—– -net/total- —procs— —-swap— —system–

usr sys idl wai hiq siq| read writ| 1m 5m 15m | used buff cach free| recv send|run blk new| used free| int csw

1 0 98 0 0 0|1404B 41k|0.12 0.19 0.18|1458M 125M 13.6G 611M| 0 0 |0.0 0 0.4| 286M 7730M| 410 2134

17 1 82 0 0 0| 0 32k|0.19 0.21 0.18|1458M 125M 13.6G 611M| 51k 98k| 0 0 0| 286M 7730M|2540 2828

16 1 83 0 0 0| 0 0 |0.19 0.21 0.18|1458M 125M 13.6G 611M| 57k 103k| 0 0 0| 286M 7730M|2530 2862

17 1 82 0 0 0| 0 0 |0.19 0.21 0.18|1458M 125M 13.6G 611M| 52k 96k| 0 0 0| 286M 7730M|2498 2810

Dstat还支持将收集结果导出csv文件中。

[root@xxx-MIGPC-DB ~]# dstat -c –output res.csv

—-total-cpu-usage—-

usr sys idl wai hiq siq

1 0 98 0 0 0

18 1 82 0 0 0

17 1 82 0 0 0

17 1 82 0 0 0

18 1 82 0 0 0

16 1 83 0 0 0

16 1 83 0 0 0

16 1 83 0 0 0

15 1 84 0 0 0

17 1 83 0 0 0

[root@xxx-MIGPC-DB ~]# ls -l | grep res.csv

-rw-r–r– 1 root root 1955 Dec 3 10:28 res.csv

csv还是比较规整的类型。

3、结论

当我们进行操作系统层面全面监控的时候,Dstat作为一个开源工具,还是比较有实际价值的。

经验是由痛苦中粹取出来的

使用Dstat来进行Linux综合性能诊断

相关文章:

你感兴趣的文章:

标签云: