浅谈对linux性能监控命令iostat的理解

Posted EbowTang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了浅谈对linux性能监控命令iostat的理解相关的知识,希望对你有一定的参考价值。

iostat 监视linux的磁盘I/O子命令

iostat是I/O statistics(输入/输出统计)的缩写,用来动态监视系统的磁盘操作活动。

通过iostat方便查看CPU、网卡、tty设备、磁盘、CD-ROM 等等设备的活动情况, 负载信息。

1. 命令格式

iostat[参数][时间][次数]

2. 命令参数

-C 显示CPU使用情况

-d 显示磁盘使用情况

-k 以 KB 为单位显示

-m 以 M 为单位显示

-N 显示磁盘阵列(LVM) 信息

-n 显示NFS 使用情况

-p[磁盘] 显示磁盘和分区的情况

-t 显示终端和CPU的信息

-x 显示详细信息

-V 显示版本信息

3. 工具实例

实例1:iostat  显示所有设备负载情况

cpu属性值说明:

%user:CPU处在用户模式下的时间百分比。

%nice:CPU处在带NICE值的用户模式下的时间百分比。

%system:CPU处在系统模式下的时间百分比。

%iowait:CPU等待输入输出完成时间的百分比。(%iowait: This number shows the % of time the CPU is wasting in waiting for IO.

%steal:管理程序维护另一个虚拟处理器时,虚拟CPU的无意识等待时间百分比。

%idle:CPU空闲时间百分比。

注:

如果%iowait的值过高,表示硬盘存在I/O瓶颈,CPU用来等待IO完成的时间过多

%idle值高,表示CPU较空闲,

如果%idle值高但系统响应慢时,有可能是CPU等待分配内存,此时应加大内存容量。

%idle值如果持续低于10,那么系统的CPU处理能力相对较低,表明系统中最需要解决的资源是CPU。

iostat disk属性值说明:

为了看懂Linux的磁盘IO指标,先了解一些常见的缩写习惯:

r是read,w是write,

rq是request,qu是queue,sz是size的,a是average,tm是time,svc是service。

  1. rrqm/s 和 wrqm/s(可无视)

每秒合并的读和写请求。"合并的"意味着操作系统从队列中拿出多个逻辑请求合并为一个请求到实际磁盘。

  1. r/s 和 w/s(吞吐量,重要)

每秒发送到设备的读和写请求数。

  1. rsec/s 和 wsec/s(可无视)

每秒读和写的扇区数。有些系统也输出为rKB/s和wKB/s ,意味每秒读写的千字节数。(iostat -dkx interval times)

  1. avgrq-sz

请求的扇区数。(读扇区数 + 写扇区数) / (读请求次数 + 写请求次数)

  1. avgqu-sz

在设备队列中等待的请求数。即队列驻留的平均长度。

  1. await(IO等待时间,重要指标)

每个IO请求花费的时间,包括在队列中的等待时间和实际请求(服务)时间。

  1. svctm(可无视,意义不大,是通过r/s+w/s计算得到

实际请求(服务)时间,以毫秒为单位,不包括排队时间。

  1. %util(磁盘繁忙度,重要)

至少有一个活跃请求所占时间的百分比。更好的说法应该是,服务时间所占的百分比。

重要参数:(记住下面的即可)

参数

说明

备注

r/s,w/s

每秒读,写IO完成次数

r/s + w/s = 当前IOPS,注意util为100%时的IOPS非设IOPS

rMB/swMB/s

每秒读,写数据量(mb为单位)

磁盘读写吞度量

avgqu-sz

平均等待处理的IO请求队列长度

该值越大,表示排队等待处理的IO越多

avgrq-sz

请求的扇区数。

即IO大小

await

平均每次IO请求等待时间(包括等待时间和处理时间毫秒为单位)

即IO的响应时间,对于1万转的机械硬盘,持续超过20ms该磁盘设备响应慢svctm 一般要小于 await

%util

IO队列非空的时间比率

util = (r/s+w/s) * (svctm/1000)表征磁盘繁忙度,1秒内磁盘非空闲时间百分比

小结与案例

IO瓶颈的症状:

1. %util 很高 (磁盘繁忙不一定代表

2. await 远大于svctm ,await值不宜过大,一般不大于20ms

3. avgqu-sz 比较大

4. r/sw/s吞吐量大(不通磁盘性能表现不一样)

可以记住的命令为:

iostat -xm 1 //每隔一秒,以MB详细显示CPU和磁盘设备的信息

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

                4.57      0.00    4.38        0.00       0.00      91.06

Device: rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util

sda     0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00

sdb     0.00     0.00    0.00   22.00     0.00     0.18    16.36     0.00    0.00    0.00    0.00   0.00   0.00

sdc     0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00

案例1:

以写200g文件时,后台读写性能监控结果为:

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           0.00    0.00    1.51    3.49    0.00   95.00

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util

sdb               0.00    29.00    4.00 2206.00     0.02   551.12   510.74   126.65   54.74   45.00   54.76   0.45 100.00

sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           0.00    0.00    1.89    3.27    0.00   94.85

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util

sdb               0.00    20.00    4.00 2177.00     0.02   543.10   509.99   127.74   59.12   57.00   59.13   0.46 100.00

sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           0.06    0.00    1.26    3.92    0.00   94.76

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util

sdb               0.00     0.00    5.00 2122.00     0.02   530.50   510.82   139.54   65.66   11.20   65.79   0.47 100.00

sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           0.00    0.00    1.76    3.27    0.00   94.96

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util

sdb               0.00     0.00    5.00 2338.00     0.02   584.50   510.92   142.20   60.91    0.80   61.04   0.43 100.00

sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           0.00    0.00    1.70    3.31    0.00   94.99

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util

sdb               0.00     0.00    5.00 2338.00     0.02   584.50   510.92   142.06   60.49    1.60   60.62   0.43 100.00

sda               0.00     5.00    0.00   12.00     0.00     0.07    11.33     0.00    0.00    0.00    0.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           0.00    0.00    1.54    3.30    0.00   95.16

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util

sdb               0.00    26.00    5.00 2324.00     0.02   580.61   510.57   133.13   57.22   19.20   57.30   0.43 100.00

sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle

           0.00    0.00    1.73    3.37    0.00   94.90

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util

sdb               0.00    20.00    5.00 2244.00     0.02   560.59   510.50   142.58   63.12    1.60   63.26   0.44 100.00

sda               0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00    0.00    0.00   0.00   0.00

而此时top命令的结果:

top - 14:27:50 up 2 days, 21:26,  4 users,  load average: 2.01, 1.18, 0.54

Tasks: 558 total,   1 running, 557 sleeping,   0 stopped,   0 zombie

Cpu(s):  0.0%us,  1.8%sy,  0.0%ni, 94.9%id,  3.3%wa,  0.0%hi,  0.0%si,  0.0%st

Mem:  263253924k total, 217242864k used, 46011060k free,   487436k buffers

Swap: 30000124k total,        0k used, 30000124k free, 208157632k cached

   PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                                                                                                                                                        

 95588 root      20   0 1033m 1.0g 1772 D   55  0.4   2:29.21 dd                                                                                                                                                                                                             

 84349 root      20   0     0    0    0 D    8  0.0   0:19.39 kworker/u514:2                                                                                                                                                                                                 

  3137 root      10 -10 2411m 420m  11m S    1  0.2  51:46.72 ovs-vswitchd                                                                                                                                                                                                    

 96829 root      20   0 17784 2660 1936 R    0  0.0   0:00.03 top                                                                                                                                                                                                             

     1 root      20   0 24608 3508 2332 S    0  0.0   0:03.06 init                                                                                                                                                                                                            

     2 root      20   0     0    0    0 S    0  0.0   0:00.02 kthreadd                                                                                                                                                                                                        

     3 root      20   0     0    0    0 S    0  0.0   0:02.21 ksoftirqd/0                                                                                                                                                                                                     

     5 root       0 -20     0    0    0 S    0  0.0   0:00.00 kworker/0:0H                                                                                                                                                                                                    

     6 root      20   0     0    0    0 S    0  0.0   0:00.01 kworker/u512:0                                                                                                                                                                                                  

     8 root      20   0     0    0    0 S    0  0.0   2:12.07 rcu_sched                                                                                                                                                                                                       

     9 root      20   0     0    0    0 S    0  0.0   0:00.00 rcu_bh                                                                                                                                                                                                          

    10 root      20   0     0    0    0 S    0  0.0   1:14.99 rcuos/0                                                                                                                                                                                                         

    11 root      20   0     0    0    0 S    0  0.0   0:00.00 rcuob/0                                                                                                                                                                                                         

    12 root      RT   0     0    0    0 S    0  0.0   0:00.23 migration/0                                                                                                                                                                                                     

    13 root      RT   0     0    0    0 S    0  0.0   0:00.34 watchdog/0                                                                                                                                                                                                      

    14 root      RT   0     0    0    0 S    0  0.0   0:00.32 watchdog/1                                                                                                                                                                                                      

    15 root      RT   0     0    0    0 S    0  0.0   0:00.23 migration/1                                                                                                                                                                                                     

    16 root      20   0     0    0    0 S    0  0.0   0:01.93 ksoftirqd/1                                                                                                                                                                                                     

    18 root       0 -20     0    0    0 S    0  0.0   0:00.00 kworker/1:0H                                                                                                                                                                                                    

    19 root      20   0     0    0    0 S    0  0.0   0:05.65 rcuos/1                                                                                                                                                                                                         

    20 root      20   0     0    0    0 S    0  0.0   0:00.00 rcuob/1                                                                                                                                                                                                         

    21 root      RT   0     0    0    0 S    0  0.0   0:00.26 watchdog/2                                                                                                                                                                                                      

    22 root      RT   0     0    0    0 S    0  0.0   0:00.23 migration/2                                                                                                                                                                                                     

    23 root      20   0     0    0    0 S    0  0.0   0:01.76 ksoftirqd/2                                                                                                                                                                                                     

    24 root      20   0     0    0    0 S    0  0.0   0:00.00 kworker/2:0                                                                                                                                                                                                     

    25 root       0 -20     0    0    0 S    0  0.0   0:00.00 kworker/2:0H                                                                                                                                                                                                    

    26 root      20   0     0    0    0 S    0  0.0   0:03.50 rcuos/2                                                                                                                                                                                                         

    27 root      20   0     0    0    0 S    0  0.0   0:00.00 rcuob/2                                                                                                                                                                                                         

    28 root      RT   0     0    0    0 S    0  0.0   0:00.26 watchdog/3                                                                                                                                                                                                      

    29 root      RT   0     0    0    0 S    0  0.0   0:00.23 migration/3                                                                                                                                                                                                     

    30 root      20   0     0    0    0 S    0  0.0   0:01.66 ksoftirqd/3                                                                                                                                                                                                     

    31 root      20   0     0    0    0 S    0  0.0   0:00.00 kworker/3:0                                                                                                                                                                                                     

    32 root       0 -20     0    0    0 S    0  0.0   0:00.00 kworker/3:0H                                                                                                                                                                                                    

    33 root      20   0     0    0    0 S    0  0.0   0:03.31 rcuos/3                                                                                                                                                                                                         

    34 root      20   0     0    0    0 S    0  0.0   0:00.00 rcuob/3                                                                                                                                                                                                         

    35 root      RT   0     0    0    0 S    0  0.0   0:00.26 watchdog/4                                                                                                                                                                                                     

    36 root      RT   0     0    0    0 S    0  0.0   0:00.23 migration/4                                                                                                                                                                                                    

    37 root      20   0     0    0    0 S    0  0.0   0:01.81 ksoftirqd/4                                                                                                                                                                                                    

    38 root      20   0     0    0    0 S    0  0.0   0:00.05 kworker/4:0                                                                                                                                                                                                    

    39 root       0 -20     0    0    0 S    0  0.0   0:00.00 kworker/4:0H                                                                                                                                                                                                    

    40 root      20   0     0    0    0 S    0  0.0   0:02.91 rcuos/4                                                                                                                                                                                                         

    41 root      20   0     0    0    0 S    0  0.0   0:00.00 rcuob/4                                                                                                                                                                                                         

    42 root      RT   0     0    0    0 S    0  0.0   0:00.27 watchdog/5                                                                                                                                                                                                      

    43 root      RT   0     0    0    0 S    0  0.0   0:00.24 migration/5                                                                                                                                                                                                     

    44 root      20   0     0    0    0 S    0  0.0   0:01.58 ksoftirqd/5                                                                                                                                                                                                     

    46 root       0 -20     0    0    0 S    0  0.0   0:00.00 kworker/5:0H                                                                                                                                                                                                    

    47 root      20   0     0    0    0 S    0  0.0   0:03.28 rcuos/5                                                                                                                                                                                                         

    48 root      20   0     0    0    0 S    0  0.0   0:00.00 rcuob/5                                                                                                                                                                                                         

    49 root      RT   0     0    0    0 S    0  0.0   0:00.26 watchdog/6                                                                                                                                                                                                      

    50 root      RT   0     0    0    0 S    0  0.0   0:00.24 migration/6                                                                                                                                                                                                     

    51 root      20   0     0    0    0 S    0  0.0   0:01.83 ksoftirqd/6                                                                                                                                                                                                     

    52 root      20   0     0    0    0 S    0  0.0   0:00.00 kworker/6:0                                                                                                                                                                                                     

    53 root       0 -20     0    0    0 S    0  0.0   0:00.00 kworker/6:0H  

以上是关于浅谈对linux性能监控命令iostat的理解的主要内容,如果未能解决你的问题,请参考以下文章

vmstat和iostat命令进行Linux性能监控

使用vmstat和iostat命令进行Linux性能监控

监控io性能free命令ps命令查看网络状态linux下抓包

Linux磁盘I/O性能监控之iostat详解

Linux的IO性能监控工具iostat详解

Linux的IO性能监控工具iostat详解