Linux 系统中的 iostat 是 I/O statistics (输入/输出统计)的缩写,iostat 工具将对系统的磁盘操作活动进行监视。它的特点是汇报磁盘活动统计情况,同时也汇报出CPU使用情况。同 vmstat 一样,iostat 也有一个弱点,就是它不能对某个进程进行深入分析,仅对系统的整体情况进行分析。iostat 属于 sysstat 软件包。可以用 yum install stsstat 直接安装;
命令格式 - iostat [参数] [时间] [次数]
命令功能 - 通过 iostat 方便查看 CPU、网卡、tty设备、磁盘、CD-ROM 等等设备的活动情况,负载信息
命令参数 -
命令实例 -
实例一:显示所有设备负载情况
命令
xxxxxxxxxx11iostat输出
xxxxxxxxxx151[root@CT1186 ~]# iostat2Linux 2.6.18-128.el5 (CT1186) 2012年12月28日34avg-cpu: %user %nice %system %iowait %steal %idle5 8.30 0.02 5.07 0.17 0.00 86.4467Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn8sda 22.73 43.70 487.42 674035705 75179419529sda1 0.00 0.00 0.00 2658 53610sda2 0.11 3.74 3.51 57721595 5420221611sda3 0.98 0.61 17.51 9454172 27002336812sda4 0.00 0.00 0.00 6 013sda5 6.95 0.12 108.73 1924834 167712353614sda6 2.20 0.18 31.22 2837260 48148805615sda7 12.48 39.04 326.45 602094508 5035104240说明
cpu属性值说明:
%user:CPU处在用户模式下的时间百分比。
%nice:CPU处在带NICE值的用户模式下的时间百分比。
%system:CPU处在系统模式下的时间百分比。
%iowait:CPU等待输入输出完成时间的百分比。
%steal:管理程序维护另一个虚拟处理器时,虚拟CPU的无意识等待时间百分比。
%idle:CPU空闲时间百分比。
备注 :如果%iowait的值过高,表示硬盘存在I/O瓶颈,%idle值高,表示CPU较空闲,如果%idle值高但系统响应慢时,有可能是CPU等待分配内存,此时应加大内存容量。%idle值如果持续低于10,那么系统的CPU处理能力相对较低,表明系统中最需要解决的资源是CPU。
disk属性值说明:
rrqm/s: 每秒进行 merge 的读操作数目。即 rmerge/s
wrqm/s: 每秒进行 merge 的写操作数目。即 wmerge/s
r/s: 每秒完成的读 I/O 设备次数。即 rio/s
w/s: 每秒完成的写 I/O 设备次数。即 wio/s
rsec/s: 每秒读扇区数。即 rsect/s
wsec/s: 每秒写扇区数。即 wsect/s
rkB/s: 每秒读K字节数。是 rsect/s 的一半,因为每扇区大小为512字节。
wkB/s: 每秒写K字节数。是 wsect/s 的一半。
avgrq-sz: 平均每次设备I/O操作的数据大小 (扇区)。
avgqu-sz: 平均I/O队列长度。
await: 平均每次设备I/O操作的等待时间 (毫秒)。
svctm: 平均每次设备I/O操作的服务时间 (毫秒)。
%util: 一秒中有百分之多少的时间用于 I/O 操作,即被io消耗的cpu百分比
备注 :如果 %util 接近 100%,说明产生的I/O请求太多,I/O系统已经满负荷,该磁盘可能存在瓶颈。如果 svctm 比较接近 await,说明 I/O 几乎没有等待时间;如果 await 远大于 svctm,说明I/O 队列太长,io响应太慢,则需要进行必要优化。如果avgqu-sz比较大,也表示有当量io在等待。
实例二:定时显示所有信息
命令
xxxxxxxxxx11iostat 2 3输出
xxxxxxxxxx411[root@CT1186 ~]# iostat 2 32Linux 2.6.18-128.el5 (CT1186) 2012年12月28日34avg-cpu: %user %nice %system %iowait %steal %idle5 8.30 0.02 5.07 0.17 0.00 86.4467Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn8sda 22.73 43.70 487.42 674035705 75179472969sda1 0.00 0.00 0.00 2658 53610sda2 0.11 3.74 3.51 57721595 5420221611sda3 0.98 0.61 17.51 9454172 27002360812sda4 0.00 0.00 0.00 6 013sda5 6.95 0.12 108.73 1924834 167712564014sda6 2.20 0.18 31.22 2837260 48148815215sda7 12.48 39.04 326.44 602094508 50351071441617avg-cpu: %user %nice %system %iowait %steal %idle18 8.88 0.00 7.94 0.19 0.00 83.001920Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn21sda 6.00 0.00 124.00 0 24822sda1 0.00 0.00 0.00 0 023sda2 0.00 0.00 0.00 0 024sda3 0.00 0.00 0.00 0 025sda4 0.00 0.00 0.00 0 026sda5 0.00 0.00 0.00 0 027sda6 0.00 0.00 0.00 0 028sda7 6.00 0.00 124.00 0 2482930avg-cpu: %user %nice %system %iowait %steal %idle31 9.12 0.00 7.81 0.00 0.00 83.073233Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn34sda 4.00 0.00 84.00 0 16835sda1 0.00 0.00 0.00 0 036sda2 0.00 0.00 0.00 0 037sda3 0.00 0.00 0.00 0 038sda4 0.00 0.00 0.00 0 039sda5 0.00 0.00 0.00 0 040sda6 4.00 0.00 84.00 0 16841sda7 0.00 0.00 0.00 0 0 说明
每隔 2秒刷新显示,且显示3次
实例三:显示指定磁盘信息
命令
xxxxxxxxxx11iostat -d sda1输出
xxxxxxxxxx51[root@CT1186 ~]# iostat -d sda12Linux 2.6.18-128.el5 (CT1186) 2012年12月28日34Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn5sda1 0.00 0.00 0.00 2658 536说明
实例四:显示tty和CPU信息
命令
xxxxxxxxxx11iostat -t输出
xxxxxxxxxx161[root@CT1186 ~]# iostat -t2Linux 2.6.18-128.el5 (CT1186) 2012年12月28日34Time: 14时58分35秒5avg-cpu: %user %nice %system %iowait %steal %idle6 8.30 0.02 5.07 0.17 0.00 86.4478Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn9sda 22.73 43.70 487.41 674035705 751795786410sda1 0.00 0.00 0.00 2658 53611sda2 0.11 3.74 3.51 57721595 5420221612sda3 0.98 0.61 17.51 9454172 27002434413sda4 0.00 0.00 0.00 6 014sda5 6.95 0.12 108.73 1924834 167712880815sda6 2.20 0.18 31.22 2837260 48148871216sda7 12.48 39.04 326.44 602094508 5035113248 说明
实例五:以M为单位显示所有信息
命令
xxxxxxxxxx11iostat -m输出
xxxxxxxxxx151[root@CT1186 ~]# iostat -m2Linux 2.6.18-128.el5 (CT1186) 2012年12月28日34avg-cpu: %user %nice %system %iowait %steal %idle5 8.30 0.02 5.07 0.17 0.00 86.4467Device: tps MB_read/s MB_wrtn/s MB_read MB_wrtn8sda 22.72 0.02 0.24 329119 36708819sda1 0.00 0.00 0.00 1 010sda2 0.11 0.00 0.00 28184 2646511sda3 0.98 0.00 0.01 4616 13184812sda4 0.00 0.00 0.00 0 013sda5 6.95 0.00 0.05 939 81891114sda6 2.20 0.00 0.02 1385 23510215sda7 12.48 0.02 0.16 293991 2458553 说明
实例六:查看TPS和吞吐量信息
命令
xxxxxxxxxx11iostat -d -k 1 1输出
xxxxxxxxxx121[root@CT1186 ~]# iostat -d -k 1 12Linux 2.6.18-128.el5 (CT1186) 2012年12月28日34Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn5sda 22.72 21.85 243.71 337017916 37589843406sda1 0.00 0.00 0.00 1329 2687sda2 0.11 1.87 1.76 28860797 271011088sda3 0.98 0.31 8.75 4727086 1350125089sda4 0.00 0.00 0.00 3 010sda5 6.95 0.06 54.37 962481 83856614811sda6 2.20 0.09 15.61 1418630 24074471212sda7 12.48 19.52 163.22 301047254 2517559596 说明
tps:该设备每秒的传输次数(Indicate the number of transfers per second that were issued to the device.)。“一次传输”意思是“一次I/O请求”。多个逻辑请求可能会被合并为“一次I/O请求”。“一次传输”请求的大小是未知的。
kB_read/s:每秒从设备(drive expressed)读取的数据量;
kB_wrtn/s:每秒向设备(drive expressed)写入的数据量;
kB_read:读取的总数据量;kB_wrtn:写入的总数量数据量;
这些单位都为Kilobytes。
上面的例子中,我们可以看到磁盘sda以及它的各个分区的统计数据,当时统计的磁盘总TPS是22.73,下面是各个分区的TPS。(因为是瞬间值,所以总TPS并不严格等于各个分区TPS的总
实例七:查看设备使用率(%util)、响应时间(await)
命令
xxxxxxxxxx11iostat -d -x -k 1 1输出
xxxxxxxxxx121[root@CT1186 ~]# iostat -d -x -k 1 12Linux 2.6.18-128.el5 (CT1186) 2012年12月28日34Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util5sda 0.44 38.59 0.40 22.32 21.85 243.71 23.37 0.04 1.78 4.20 9.546sda1 0.00 0.00 0.00 0.00 0.00 0.00 18.90 0.00 8.26 6.46 0.007sda2 0.36 0.43 0.11 0.01 1.87 1.76 63.57 0.01 63.75 1.94 0.028sda3 0.00 1.24 0.04 0.95 0.31 8.75 18.42 0.04 39.77 8.73 0.869sda4 0.00 0.00 0.00 0.00 0.00 0.00 2.00 0.00 19.67 19.67 0.0010sda5 0.00 6.65 0.00 6.94 0.06 54.37 15.67 0.26 36.81 4.48 3.1111sda6 0.00 1.71 0.01 2.19 0.09 15.61 14.29 0.03 12.40 5.84 1.2812sda7 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) 类似于收款台前有人排队的时间比例
实例八:查看CPU状态
命令
xxxxxxxxxx11iostat -c 1 3输出
xxxxxxxxxx111[root@CT1186 ~]# iostat -c 1 32Linux 2.6.18-128.el5 (CT1186) 2012年12月28日34avg-cpu: %user %nice %system %iowait %steal %idle5 8.30 0.02 5.07 0.17 0.00 86.4467avg-cpu: %user %nice %system %iowait %steal %idle8 8.64 0.00 5.38 0.00 0.00 85.98910avg-cpu: %user %nice %system %iowait %steal %idle11 7.62 0.00 5.12 0.50 0.00 86.75说明