iostat

命令简介

iostat主要用于监控系统设备的IO负载情况

命令描述

The  first report generated by the iostat command provides statistics concerning the time since the system was booted

iostat首次运行时显示自系统启动开始的各项统计信息,之后运行iostat将显示自上次运行该命令以后的统计信息。

iostat -d -k 2

-d:显示设备(磁盘)使用状态;-k默写使用block为单位的列强制使用Kilobytes为单位;2表示时间间隔每2秒执行一次iostat命令

iostat -d -k 1 10
Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda              39.29        21.14         1.44  441339807   29990031
sda1              0.00         0.00         0.00       1623        523
sda2              1.32         1.43         4.54   29834273   94827104
sda3              6.30         0.85        24.95   17816289  520725244
sda5              0.85         0.46         3.40    9543503   70970116
sda6              0.00         0.00         0.00        550        236
sda7              0.00         0.00         0.00        406          0
sda8              0.00         0.00         0.00        406          0
sda9              0.00         0.00         0.00        406          0
sda10            60.68        18.35        71.43  383002263 1490928140

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda             327.55      5159.18       102.04       5056        100
sda1              0.00         0.00         0.00          0          0
tps:indicate the amount of transfers per second were issued to the device
设备每秒传输次数,一次传输意思是一次IO请求,一次IO请求可能由多个逻辑请求组成,一次传输请求的大小是未知的
kB_read/s:indicate the amount of data read from the device expressed in a number of blocks per second
每秒从设备读取的数据量
kB_wrtn/s:每秒写入设备的数据量
kB_read :从设备读取数据总量
kB_wrtn:写入设备的数据总量
-x参数:用于显示和io相关的扩展数据
iostat -d -x -k 1 10
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda          1.56  28.31  7.80 31.49   42.51    2.92    21.26     1.46     1.16     0.03    0.79   2.62  10.28
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda          2.00  20.00 381.00  7.00 12320.00  216.00  6160.00   108.00    32.31     1.75    4.50   2.17  84.20
rrqm/s:the number of  read requests merged per second that were queuede to the device
每秒这个设备的相关读取求书被merge的数量
wrqm/s:每秒这个设备相关的写入请求被merge数

r/s:The number of read requests that were issued to the device per second.

w/s:The number of write requests that were issued to the device per second.

rsec/s:The number of sectors read from the device per second.

每秒从相关设备读取的扇区数

wsec/s:The number of sectors written to the device per second.

每秒写入相关设备的扇区数

rkB/s:The number of kilobytes read from the device per second.

wkB/s:The number of kilobytes written to the device per second.

avgrq-sz:The average size (in sectors) of the requests that were issued to the device.

平均请求扇区的大小

avgqu-sz:The average queue length of the requests that were issued to the device.

是平均请求队列的长度。毫无疑问,队列长度越短越好。 

await:The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.

每一个IO请求的处理的平均时间(单位是微秒毫秒)。这里可以理解为IO的响应时间,一般地系统IO响应时间应该低于5ms,如果大于10ms就比较大了。

svctm:The average service time (in milliseconds) for I/O requests that were issued to the device. Warning! Do not trust this field any more. This field will be removed in a future sysstat version.表示平均每次设备I/O操作的服务时间(以毫秒为单位)。如果svctm的值与await很接近,表示几乎没有I/O等待,磁盘性能很好,如果await的值远高于svctm的值,则表示I/O队列等待太长, 系统上运行的应用程序将变慢。

%util:Percentage of elapsed time during which I/O requests were issued to the device (bandwidth utilization for the device). Device saturation occurs when this value is close to 100%.

 在统计时间内所有处理IO时间,除以总共统计时间。例如,如果统计间隔1秒,该设备有0.8秒在处理IO,而0.2秒闲置,那么该设备的%util = 0.8/1 = 80%,所以该参数暗示了设备的繁忙程度
。一般地,如果该参数是100%表示设备已经接近满负荷运行了(当然如果是多磁盘,即使%util是100%,因为磁盘的并发能力,所以磁盘使用未必就到了瓶颈)

179/5000
在向设备发出的输入/输出请求的时间百分比(设备的带宽利用率)。当这个值接近100%时,设备饱和度就会发生。

命令实例

实例一

ostat -d -k 1 |grep sda10
Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda10            60.72        18.95        71.53  395637647 1493241908
sda10           299.02      4266.67       129.41       4352        132
sda10           483.84      4589.90      4117.17       4544       4076
sda10           218.00      3360.00       100.00       3360        100
sda10           546.00      8784.00       124.00       8784        124
sda10           827.00     13232.00       136.00      13232        136

上面看到,磁盘每秒传输次数平均约400;每秒磁盘读取约5MB,写入约1MB。

 

iostat -d -x -k 1
Device:    rrqm/s wrqm/s   r/s   w/s  rsec/s  wsec/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda          1.56  28.31  7.84 31.50   43.65    3.16    21.82     1.58     1.19     0.03    0.80   2.61  10.29
sda          1.98  24.75 419.80  6.93 13465.35  253.47  6732.67   126.73    32.15     2.00    4.70   2.00  85.25
sda          3.06  41.84 444.90 54.08 14204.08 2048.98  7102.04  1024.49    32.57     2.10    4.21   1.85  92.24

可以看到磁盘的平均响应时间<5ms,磁盘使用率>80。磁盘响应正常,但是已经很繁忙了。

实例二:

iostat -d -x -k 1 1

输出:

[root@CT1186 ~]# iostat -d -x -k 1 1
Linux 2.6.18-128.el5 (CT1186)   2012年12月28日

Device:         rrqm/s   wrqm/s   r/s   w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %util
sda               0.44    38.59  0.40 22.32    21.85   243.71    23.37     0.04    1.78   4.20   9.54
sda1              0.00     0.00  0.00  0.00     0.00     0.00    18.90     0.00    8.26   6.46   0.00
sda2              0.36     0.43  0.11  0.01     1.87     1.76    63.57     0.01   63.75   1.94   0.02
sda3              0.00     1.24  0.04  0.95     0.31     8.75    18.42     0.04   39.77   8.73   0.86
sda4              0.00     0.00  0.00  0.00     0.00     0.00     2.00     0.00   19.67  19.67   0.00
sda5              0.00     6.65  0.00  6.94     0.06    54.37    15.67     0.26   36.81   4.48   3.11
sda6              0.00     1.71  0.01  2.19     0.09    15.61    14.29     0.03   12.40   5.84   1.28
sda7              0.08    28.56  0.25 12.24    19.52   163.22    29.28     0.27   21.46   5.00   6.25 

 

说明:

rrqm/s:  每秒进行 merge 的读操作数目.即 delta(rmerge)/s

wrqm/s: 每秒进行 merge 的写操作数目.即 delta(wmerge)/s

r/s:  每秒完成的读 I/O 设备次数.即 delta(rio)/s

w/s:  每秒完成的写 I/O 设备次数.即 delta(wio)/s

rsec/s:  每秒读扇区数.即 delta(rsect)/s

wsec/s: 每秒写扇区数.即 delta(wsect)/s

rkB/s:  每秒读K字节数.是 rsect/s 的一半,因为每扇区大小为512字节.(需要计算)

wkB/s:  每秒写K字节数.是 wsect/s 的一半.(需要计算)

avgrq-sz:平均每次设备I/O操作的数据大小 (扇区).delta(rsect+wsect)/delta(rio+wio)

avgqu-sz:平均I/O队列长度.即 delta(aveq)/s/1000 (因为aveq的单位为毫秒).

await:  平均每次设备I/O操作的等待时间 (毫秒).即 delta(ruse+wuse)/delta(rio+wio)

svctm: 平均每次设备I/O操作的服务时间 (毫秒).即 delta(use)/delta(rio+wio)

%util: 一秒中有百分之多少的时间用于 I/O 操作,或者说一秒中有多少时间 I/O 队列是非空的,即 delta(use)/s/1000 (因为use的单位为毫秒)

 

如果 %util 接近 100%,说明产生的I/O请求太多,I/O系统已经满负荷,该磁盘可能存在瓶颈。

idle小于70% IO压力就较大了,一般读取速度有较多的wait。

同时可以结合vmstat 查看查看b参数(等待资源的进程数)和wa参数(IO等待所占用的CPU时间的百分比,高过30%时IO压力高)。

另外 await 的参数也要多和 svctm 来参考。差的过高就一定有 IO 的问题。

avgqu-sz 也是个做 IO 调优时需要注意的地方,这个就是直接每次操作的数据的大小,如果次数多,但数据拿的小的话,其实 IO 也会很小。如果数据拿的大,才IO 的数据会高。也可以通过 avgqu-sz × ( r/s or w/s ) = rsec/s or wsec/s。也就是讲,读定速度是这个来决定的。

svctm 一般要小于 await (因为同时等待的请求的等待时间被重复计算了),svctm 的大小一般和磁盘性能有关,CPU/内存的负荷也会对其有影响,请求过多也会间接导致 svctm 的增加。await 的大小一般取决于服务时间(svctm) 以及 I/O 队列的长度和 I/O 请求的发出模式。如果 svctm 比较接近 await,说明 I/O 几乎没有等待时间;如果 await 远大于 svctm,说明 I/O 队列太长,应用得到的响应时间变慢,如果响应时间超过了用户可以容许的范围,这时可以考虑更换更快的磁盘,调整内核 elevator 算法,优化应用,或者升级 CPU。

队列长度(avgqu-sz)也可作为衡量系统 I/O 负荷的指标,但由于 avgqu-sz 是按照单位时间的平均值,所以不能反映瞬间的 I/O 洪水。

 

       形象的比喻:
       r/s+w/s 类似于交款人的总数
      平均队列长度(avgqu-sz)类似于单位时间里平均排队人的个数
      平均服务时间(svctm)类似于收银员的收款速度
      平均等待时间(await)类似于平均每人的等待时间
      平均I/O数据(avgrq-sz)类似于平均每人所买的东西多少
       I/O 操作率 (%util)类似于收款台前有人排队的时间比例

       设备IO操作:总IO(io)/s = r/s(读) +w/s(写) =1.46 + 25.28=26.74
      平均每次设备I/O操作只需要0.36毫秒完成,现在却需要10.57毫秒完成,因为发出的 请求太多(每秒26.74个),假如请求时同时发出的,可以这样计算平均等待时间:
      平均等待时间=单个I/O服务器时间*(1+2+...+请求总数-1)/请求总数 
       每秒发出的I/0请求很多,但是平均队列就4,表示这些请求比较均匀,大部分处理还是比较及时。

参考文献:
http://www.cnblogs.com/peida/archive/2012/12/28/2837345.html
http://www.cnblogs.com/ggjucheng/archive/2013/01/13/2858810.html

 

 


你可能感兴趣的