Linux下利用iostat 监视I/O状态

-d 显示磁盘使用情况,命令参数,显示设备(磁盘)使用状态,其中iostat可以提供更丰富的IO性能状态数据,iostat命令,vmstat命令

Linux下大家能够使用 sar(一), pidstat(一), mpstat(一), vmstat(捌)
来监察和控制I/O状态

Linux的IO品质监督工具iostat详解

每一日1个linux命令(肆七):iostat命令

一、安装

 

 

yum install sysstat

Linux系统出现了品质难题,一般大家能够通过top、iostat、free、vmstat等一声令下来查看先导定位难点。其中iostat能够提供更拉长的IO性能状态数据。

有关链接:

二、参数解释

  1. 骨干使用

天天二个linux命令(四陆):vmstat命令

FILES

$iostat -d -k 1 10

/proc/stat contains system statistics.

参数 -d
表示,展现设备(磁盘)使用状态;-k某个使用block为单位的列强制行使Kilobytes为单位;1
10表示,数据展现每隔1秒刷新二遍,共呈现十遍。

 

/proc/uptime contains system uptime.

$iostat -d -k 1 10

Linux系统中的 iostat是I/O
statistics(输入/输出总计)的缩写,iostat工具将对系统的磁盘操作活动拓展监视。它的特征是报告磁盘活动计算意况,同不时候也会上报出CPU使用情状。同vmstat同样,iostat也是有一个败笔,正是它不可能对有些进程打开深远深入分析,仅对系统的总体情状打开辨析。iostat属于sysstat软件包。能够用yum
install sysstat 直接设置。  www.贰cto.com  

/proc/partitions contains disk statistics (for pre 2.5 kernels that have
been patched).

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn

一.命令格式:

/proc/diskstats contains disks statistics (for post 2.5 kernels).

sda 39.29 21.14 1.44 441339807 29990031

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

/sys contains statistics for block devices (post 2.5 kernels).

sda1 0.00 0.00 0.00 1623 523

2.下令功用:

/proc/self/mountstats contains statistics for network filesystems.

sda2 1.32 1.43 4.54 29834273 94827104

 
通过iostat方便查看CPU、网卡、tty设备、磁盘、CD-ROM
等等设施的移位情形,
负载消息。

/dev/disk contains persistent device names.

sda3 6.30 0.85 24.95 17816289 520725244

叁.命令参数:

CPU Utilization Report 

sda5 0.85 0.46 3.40 9543503 70970116

-C 显示CPU使用状态

%user    Show  the  percentage  of CPU utilization that occurred while
executing at the user level (applica-tion).

sda6 0.00 0.00 0.00 550 236

-d 展现磁盘使用情况

%nice  Show the percentage of CPU utilization that occurred while
executing at the user  level  with  nicepriority.

sda7 0.00 0.00 0.00 406 0

-k 以 KB 为单位显示

%system    Show  the percentage of CPU utilization that occurred while
executing at the system level (kernel).

sda8 0.00 0.00 0.00 406 0

-m 以 M 为单位突显

%iowait    Show the percentage of time that the CPU or CPUs were idle
during which the system had an outstand-ing disk I/O request.

sda9 0.00 0.00 0.00 406 0

-N 显示磁盘阵列(LVM) 音讯

%steal    Show the percentage of time spent in involuntary wait by the
virtual CPU or CPUs while the hypervi-sor was servicing another virtual
processor.

sda10 60.68 18.35 71.43 383002263 1490928140

-n 显示NFS 使用意况

%idle    Show the percentage of time that the CPU or CPUs were idle and
the system did not have an outstand-ing disk I/O request.

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn

-p[磁盘] 展现磁盘和分区的动静

Device Utilization Report

sda 327.55 5159.18 102.04 5056 100

-t 呈现终端和CPU的新闻

tps  Indicate  the  number  of transfers per second that were issued to
the device. A transfer is an I/O

sda1 0.00 0.00 0.00 0 0

-x 展现详细消息

      request to the device. Multiple logical requests can be combined
into a single I/O request  to  the

tps:该设施每秒的传导次数(Indicate the number of transfers per second
that were issued to the
device.)。“一遍传输”意思是“叁回I/O请求”。三个逻辑请求恐怕会被合并为“一遍I/O请求”。“壹遍传输”请求的大大小小是未知的。

-V 展现版本音讯

      device. A transfer is of indeterminate size.

kB_read/s:每秒从设备(drive
expressed)读取的数据量;kB_wrtn/s:每秒向设施(drive
expressed)写入的数据量;kB_read:读取的总的数量据量;kB_wrtn:写入的总的数量据数据量;那个单位都为Kilobytes。

肆.用到实例:

 

上边的例证中,我们得以见见磁盘sda以及它的逐壹分区的总计数据,当时计算的磁盘总TPS是3玖.2九,上边是各样分区的TPS。(因为是须臾间值,所以总TPS并不严峻等于种种分区TPS的总额)

实例壹:展现全体道具负载意况

Blk_read/s    Indicate the amount of data read from the device
expressed in a number of blocks per second. Blocks

  1. -x 参数

命令:

      are equivalent to sectors with kernels 2.4 and later and therefore
have a size of 512  bytes.  With

运用-x参数我们得以获取越来越多总计消息。

iostat

      older kernels, a block is of indeterminate size.

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

  www.2cto.com  

Blk_wrtn/s    Indicate the amount of data written to the device
expressed in a number of blocks per second.

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

[[email protected]
~]# iostat

Blk_read    The total number of blocks read.

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s rkB/s wkB/s avgrq-sz
avgqu-sz await svctm %util

Linux 2.6.18-128.el5 (CT1186)   2012年12月28日

Blk_wrtn    The total number of blocks written.

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

 

kB_read/s    Indicate the amount of data read from the device expressed
in kilobytes per second.

rrqm/s:每秒这几个设备相关的读取请求有多少被Merge了(当系统调用必要读取数据的时候,VFS将请求发到各样FS,借使FS开掘分歧的读取请求读取的是一样Block的数额,FS会将这么些请求合并Merge);wrqm/s:每秒那些装置相关的写入请求有多少被Merge了。

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

kB_wrtn/s    Indicate the amount of data written to the device
expressed in kilobytes per second.

rsec/s:每秒读取的扇区数;wsec/:每秒写入的扇区数。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;

           8.30    0.02    5.07    0.17    0.00   86.44

kB_read    The total number of kilobytes read.

await:每一个IO请求的管理的平均时间(单位是飞秒飞秒)。这里能够领略为IO的响应时间,一般地系统IO响应时间应该低于伍ms,假若赶上十ms就相当的大了。

 

kB_wrtn    The total number of kilobytes written.

%util:在计算时间内有所拍卖IO时间,除以总共总括时间。举例,若是总计间隔1秒,该道具有0.8秒在拍卖IO,而0.贰秒闲置,那么该设施的%util
= 0.8/一 =
8/10,所以该参数暗意了设备的无暇程度。一般地,假设该参数是百分百意味着设备已经临近满负荷运行了(当然如果是多磁盘,就算%util是百分百,因为磁盘的产出才能,所以磁盘使用未必就到了瓶颈)。

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read  
Blk_wrtn

MB_read/s    Indicate the amount of data read from the device expressed
in megabytes per second.

  1. -c 参数

sda              22.73        43.70       487.42  674035705 7517941952

MB_wrtn/s    Indicate the amount of data written to the device
expressed in megabytes per second.

iostat还是可以够用来获取cpu部分情形值:

sda1              0.00         0.00         0.00       2658        536

MB_read    The total number of megabytes read.

iostat -c 1 10

sda2              0.11         3.74         3.51   57721595   54202216

MB_wrtn    The total number of megabytes written.

avg-cpu: %user %nice %sys %iowait %idle

sda3              0.98         0.61        17.51    9454172  270023368

rrqm/s    The number of read requests merged per second that were queued
to the device.

1.98 0.00 0.35 11.45 86.22

sda4              0.00         0.00         0.00          6          0

wrqm/s    The number of write requests merged per second that were
queued to the device.

avg-cpu: %user %nice %sys %iowait %idle

sda5              6.95         0.12       108.73    1924834 1677123536

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

1.62 0.00 0.25 34.46 63.67

sda6              2.20         0.18        31.22    2837260  481488056

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

  1. 常见用法

sda7             12.48        39.04       326.45  602094508 5035104240

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

$iostat -d -k 1 10 #查阅TPS和吞吐量音讯

 

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

iostat -d -x -k 1 10 #翻看设备使用率(%util)、响应时间(await)

说明:

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

iostat -c 1 10 #查看cpu状态

cpu属性值表达:

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

 

%user:CPU处在用户方式下的小运百分比。

rMB/s    The number of megabytes read from the device per second.

  1. 实例解析

%nice:CPU处在带NICE值的用户情势下的时刻百分比。

wMB/s    The number of megabytes written to the device per second.

$iostat -d -k 1 |grep sda10

%system:CPU处在系统格局下的光阴百分比。

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

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn

%iowait:CPU等待输入输出完结时间的比例。

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

sda10 60.72 18.95 71.53 395637647 1493241908

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

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.

sda10 299.02 4266.67 129.41 4352 132

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

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.

sda10 483.84 4589.90 4117.17 4544 4076

备注:假设%iowait的值过高,表示硬盘存在I/O瓶颈,%idle值高,表示CPU较清闲,假诺%idle值高但系统响应慢时,有非常的大希望是CPU等待分配内部存款和储蓄器,此时应加大内部存款和储蓄器体量。%idle值假若持续低于十,那么系统的CPU管理手艺相对异常的低,评释系统中最亟需缓和的财富是CPU。

%util    Percentage  of  CPU 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%.

sda10 218.00 3360.00 100.00 3360 100

disk属性值表达:

Network Filesystem report

sda10 546.00 8784.00 124.00 8784 124

rrqm/s:  每秒举行 merge 的读操作数目。即 rmerge/s

rBlk_nor/s    Indicate the number of blocks read by applications via
the read(2) system call interface.  A  block has a size of 512 bytes.

sda10 827.00 13232.00 136.00 13232 136

wrqm/s:  每秒实行 merge 的写操作数目。即 wmerge/s

wBlk_nor/s    Indicate the number of blocks written by applications via
the write(2) system call interface.

地点看到,磁盘每秒传输次数平均约400;每秒磁盘读取约伍MB,写入约1MB。

r/s:  每秒完毕的读 I/O 设备次数。即 rio/s

rBlk_dir/s    Indicate the number of blocks read from files opened with
the O_DIRECT flag.

iostat -d -x -k 1

w/s:  每秒完毕的写 I/O 设备次数。即 wio/s

wBlk_dir/s    Indicate the number of blocks written to files opened
with the O_DIRECT flag.

Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s rkB/s wkB/s avgrq-sz
avgqu-sz await svctm %util

rsec/s:  每秒读扇区数。即 rsect/s

rBlk_svr/s    Indicate the number of blocks read from the server by the
NFS client via an NFS READ request.

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

wsec/s:  每秒写扇区数。即 wsect/s

wBlk_svr/s    Indicate the number of blocks written to the server by
the NFS client via an NFS WRITE request.

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

rkB/s:  每秒读K字节数。是 rsect/s 的八分之四,因为每扇区大小为51二字节。

rkB_nor/s    Indicate the number of kilobytes read by applications via
the read(2) system call interface.

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

wkB/s:  每秒写K字节数。是 wsect/s 的一半。

wkB_nor/s    Indicate the number of kilobytes written by applications
via the write(2) system call interface.

能够看看磁盘的平分响应时间<伍ms,磁盘使用率>80。磁盘响应正常,但是已经很艰辛了。

avgrq-sz:  平均每趟设备I/O操作的多少大小 (扇区)。

rkB_dir/s    Indicate the number of kilobytes read from files opened
with the O_DIRECT flag.

延伸:

avgqu-sz:  平均I/O队列长度。

wkB_dir/s    Indicate the number of kilobytes written to files opened
with the O_DIRECT flag.

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

await:  平均每一遍设备I/O操作的等候时间 (飞秒)。

rkB_svr/s    Indicate the number of kilobytes read from the server by
the NFS client via an NFS READ request.

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

svctm: 平均每一回设备I/O操作的服务时间 (纳秒)。

wkB_svr/s    Indicate  the number of kilobytes written to the server by
the NFS client via an NFS WRITE request.

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

%util:  1秒中有百分之多少的时光用来 I/O 操作,即被io消耗的cpu百分比

rMB_nor/s    Indicate the number of megabytes read by applications via
the read(2) system call interface.

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

备注:固然 %util 接近百分之百,表达发生的I/O请求太多,I/O系统已经满负荷,该磁盘恐怕存在瓶颈。如果svctm 相比临近 await,表达 I/O 大致一直不等待时间;假若 await 远大于
svctm,表达I/O
队列太长,io响应太慢,则供给开始展览须要优化。假若avgqu-sz一点都不小,也意味着有当量io在等待。

wMB_nor/s    Indicate the number of megabytes written by applications
via the write(2) system call interface.

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

实例2:按期呈现全数新闻

rMB_dir/s    Indicate the number of megabytes read from files opened
with the O_DIRECT flag.

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

命令:

wMB_dir/s    Indicate the number of megabytes written to files opened
with the O_DIRECT flag.

rkB/s:      每秒读K字节数.是 rsect/s
的伍分之3,因为每扇区大小为512字节.(须要总计)

iostat 2 3

rMB_svr/s    Indicate the number of megabytes read from the server by
the NFS client via an NFS READ request.

wkB/s:    每秒写K字节数.是 wsect/s 的2/肆.(需求总结)

输出:

wMB_svr/s    Indicate the number of megabytes written to the server by
the NFS client via an NFS WRITE  request.

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

 

ops/s    Indicate the number of operations that were issued to the
filesystem per second.

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

[[email protected]
~]# iostat 2 3

rops/s    Indicate the number of ’read’ operations that were issued to
the filesystem per second.

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

Linux 2.6.18-128.el5 (CT1186)   2012年12月28日

wops/s    Indicate the number of ’write’ operations that were issued to
the filesystem per second.

svctm:   平均每一趟设备I/O操作的劳务时间 (微秒).即
delta(use)/delta(rio+wio)

 

一声令下参数

%util:      壹秒中有百分之多少的时光用于 I/O 操作,或然说一秒中有些许日子
I/O 队列是非空的.即 delta(use)/s/一千 (因为use的单位为微秒)

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

-C 显示CPU使用状态

 

           8.30    0.02    5.07    0.17    0.00   86.44

-d 展现磁盘使用境况

借使 %util 接近100%,表明发生的I/O请求太多,I/O系统已经满负荷,该磁盘或者存在瓶颈.idle小于70%IO压力就异常的大了,一般读取速度有较多的wait.

 

-k 以 KB 为单位展现

再就是能够组成vmstat
查看查看b参数(等待财富的长河数)和wa参数(IO等待所占领的CPU时间的比重,高过十分三时IO压力高)

Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read  
Blk_wrtn

-m 以 M 为单位出示

别的 await 的参数也要多和 svctm 来参照他事他说加以考察.差的过高就一定有 IO 的难点.

sda              22.73        43.70       487.42  674035705 7517947296

-N 呈现磁盘阵列(LVM) 音讯

avgqu-sz 也是个做 IO
调优时需求小心的地点,那一个便是直接每一次操作的多寡的大大小小,借使次数多,但数目拿的小的话,其实
IO 也会非常的小.借使数据拿的大,才IO 的数据会高.也能够经过 avgqu-sz × ( r/s
or w/s ) = rsec/s or wsec/s.也正是讲,读定速度是以此来调节的.

sda1              0.00         0.00         0.00       2658        536

-n 展现NFS 使用情状

 

sda2              0.11         3.74         3.51   57721595   54202216

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

别的还足以参照

sda3              0.98         0.61        17.51    9454172  270023608

-t 展现终端和CPU的音信

svctm 一般要小于 await (因为与此同不经常常候等待的乞请的守候时间被重复计算了),svctm
的轻重缓急相似和磁盘品质有关,CPU/内部存储器的载重也会对其有震慑,请求过多也会间接导致
svctm 的扩大.await 的分寸相似取决于服务时间(svctm) 以及 I/O 队列的尺寸和
I/O 请求的爆发形式.借使 svctm 相比周围 await,说明 I/O
大概一向不等待时间;就算 await 远大于 svctm,表达 I/O
队列太长,应用获得的响应时间变慢,倘若响应时间超过了用户能够容许的限定,这时能够考虑更动更加快的磁盘,调解内核
elevator 算法,优化利用,或然晋级 CPU.

sda4              0.00         0.00         0.00          6          0

-x 呈现详细消息

队列长度(avgqu-sz)也可作为衡量系统 I/O 负荷的指标,但鉴于 avgqu-sz
是比照单位时间的平均值,所以无法反映弹指间的 I/O 山洪.

sda5              6.95         0.12       108.73    1924834 1677125640

-V 呈现版本音信

 

sda6              2.20         0.18        31.22    2837260  481488152

三、使用办法

外人贰个没有错的例子.(I/O 系统 vs. 超级市场排队)

sda7             12.48        39.04       326.44  602094508 5035107144

Device Utilization Report

举1个事例,大家在杂货店排队 checkout 时,怎么调整该去哪个交款台呢?
首当是看排的队人数,5位总比二十一位要快吗?
除了数人数,大家也每每看看前边人购买的事物多少,如若前方有个购买了一礼拜食物的大婶,那么能够设想换个队排了.还应该有正是收银员的快慢了,假如碰上了连
钱都点不领悟的菜鸟,这就有的等了.其它,时机也很关键,也许 六分钟前还人山人海的收款台,今后已是时过境迁,那时候交款可是很爽啊,当然,前提是这过去的
5 分钟里所做的政工比排队要有含义 (可是作者还没察觉什么样事情比排队还无聊的).

 

[root@localhost ~]# iostat -d -k 2 4

I/O 系统也和店安顿队有成都百货上千类似之处:

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