iostat命令详解
简介
iostat主要用于监控系统设备的IO负载情况,iostat首次运行时显示自系统启动开始的各项统计信息,之后运行iostat将显示自上次运行该命令以后的统计信息。用户可以通过指定统计的次数和时间来获得所需的统计信息。
iostat可以提供更丰富的IO性能状态数据,iostat命令有两个用途:
- 输出CPU的统计信息
- 输出设备和分区的I/O统计信息
语法
iostat [ -c ] [ -d ] [ -h ] [ -N ] [ -k | -m ] [ -t ] [ -V ] [ -x ] [ -z ] [ device [...] | ALL ] [ -p [ device [,...] | ALL ] ] [ interval [ count ] ]
入门使用
iostat -d -k 2
参数
-d 表示,显示设备(磁盘)使用状态;
-k某些使用block为单位的列强制使用Kilobytes为单位;
2表示,数据显示每隔2秒刷新一次。
输出如下
[](javascript:void(0)😉
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 1490928140Device: 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:(IOPS)该设备每秒的传输次数(Indicate the number of transfers per second that were issued to the device.)。"一次传输"意思是"一次I/O请求"。多个逻辑请求可能会被合并为"一次I/O请求"。"一次传输"请求的大小是未知的。kB_read/s:每秒从设备(drive expressed)读取的数据量; 单位KB
kB_wrtn/s:每秒向设备(drive expressed)写入的数据量; 单位KB
kB_read:读取的总数据量;
kB_wrtn:写入的总数量数据量;这些单位都为Kilobytes。
上面的例子中,我们可以看到磁盘sda以及它的各个分区的统计数据,当时统计的磁盘总TPS是39.29,下面是各个分区的TPS。(因为是瞬间值,所以总TPS并不严格等于各个分区TPS的总和)
指定监控的设备名称为sda,该命令的输出结果和上面命令完全相同。
iostat -d sda 2
默认监控所有的硬盘设备,现在指定只监控sda。
-x 参数
iostat还有一个比较常用的选项-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:每秒这个设备相关的读取请求有多少被Merge了(当系统调用需要读取数据的时候,VFS将请求发到各个FS,如果FS发现不同的读取请求读取的是相同Block的数据,FS会将这个请求合并Merge);wrqm/s:每秒这个设备相关的写入请求有多少被Merge了。rsec/s:每秒读取的扇区数;
wsec/:每秒写入的扇区数。
rKB/s:The number of read requests that were issued to the device per second;
wKB/s:The number of write requests that were issued to the device per second;
avgrq-sz 平均请求扇区的大小
avgqu-sz 是平均请求队列的长度。毫无疑问,队列长度越短越好。
await: 每一个IO请求的处理的平均时间(单位是微秒毫秒)。这里可以理解为IO的响应时间,一般地系统IO响应时间应该低于5ms,如果大于10ms就比较大了。这个时间包括了队列时间和服务时间,也就是说,一般情况下,await大于svctm,它们的差值越小,则说明队列时间越短,反之差值越大,队列时间越长,说明系统出了问题。
svctm 表示平均每次设备I/O操作的服务时间(以毫秒为单位)。如果svctm的值与await很接近,表示几乎没有I/O等待,磁盘性能很好,如果await的值远高于svctm的值,则表示I/O队列等待太长, 系统上运行的应用程序将变慢。%util: 在统计时间内所有处理IO时间,除以总共统计时间。例如,如果统计间隔1秒,该设备有0.8秒在处理IO,而0.2秒闲置,那么该设备的%util = 0.8/1 = 80%,所以该参数暗示了设备的繁忙程度。一般地,如果该参数是100%表示设备已经接近满负荷运行了(当然如果是多磁盘,即使%util是100%,因为磁盘的并发能力,所以磁盘使用未必就到了瓶颈)。
-c 参数
iostat还可以用来获取cpu部分状态值:
iostat -c 1 10
avg-cpu: %user %nice %sys %iowait %idle
1.98 0.00 0.35 11.45 86.22
avg-cpu: %user %nice %sys %iowait %idle
1.62 0.00 0.25 34.46 63.67
常见用法
iostat -d -k 1 10 #查看TPS和吞吐量信息(磁盘读写速度单位为KB)
iostat -d -m 2 #查看TPS和吞吐量信息(磁盘读写速度单位为MB)
iostat -d -x -k 1 10 #查看设备使用率(%util)、响应时间(await) iostat -c 1 10 #查看cpu状态
实例分析
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 [ -c | -d ] [ -k | -m ] [ -t ] [ -V ] [ -x ] [ -n ] [ -h ] [ device [ ... ] | ALL ] [ -p [ device | ALL ] ] [ interval [count ] ]
输出
参数说明:
参数 | 描述 |
---|---|
-c | The -c option is exclusive of the -d option and displays only the CPU usage report. 输出CPU统计信息。不能与-d参数同时使用。 |
-d | The -d option is exclusive of the -c option and displays only the device utilization report. 输出设备和分区的I/O统计信息。不能与-c参数同时使用。 |
-k | Display statistics in kilobytes per second instead of blocks per second. Data displayed are valid only with kernels 2.4 and newer. 用“kbytes/秒”代替“块/秒”显示统计信息。在内核2.4以及新版中才有效。 |
-m | Display statistics in megabytes per second instead of blocks or kilobytes per second. Data displayed are valid only with kernels 2.4 and newer. 用“mbytes/秒”代替“块/秒”显示统计信息。在内核2.4以及新版中才有效。 |
-t | Displays the NFS-directory statistic. Data displayed are valid only with kernels 2.6.17 and newer. This option is exclusive ot the -x option. 显示NFS目录统计信息。在内核2.6.17以及新版中才有效。不能与参数-x同时使用。 |
-V | Print version number then exit. 显示版本号并通出。 |
-x | Display extended statistics. This option is exclusive of the -p and -n, and works with post 2.5 kernels since it needs /proc/diskstats file or a mounted sysfs to get the statistics. This option may also work with older kernels (e.g. 2.4) only if extended statistics are available in /proc/partitions (the kernel needs to be patched for that). 显示扩展统计信息。不能与参数-p和-n同时使用,并且需要在内核2.5以上才能使用,因为它需要/proc/diskstats 或者 加载sysfs获取统计信息。如果只是统计/proc/partitios的扩展统计信息,这个参数可能也能在老版本的内核(如:2.4)中工作(需要给内核打补丁) |
-n | Displays the NFS-directory statistic. Data displayed are valid only with kernels 2.6.17 and newer. This option is exclusive ot the -x option. 显示NFS目录统计信息。需要内核2.6.17或更新版本才有效。不能与参数-x同时使用。 |
-h | Display the NFS report more human readable. 可读性更好的NFS目录统计信息 |
-p | The -p option is exclusive of the -x option and displays statistics for block devices and all their partitions that are used by the system. If a device name is entered on the command line, then statistics for it and all its partitions are displayed. Last, the ALL keyword indicates that statistics have to be displayed for all the block devices and partitions defined by the system, including those that have never been used. Note that this option works only with post 2.5 ker-nels. 显示系统使用的块设备和它们的分区统计信息。不能与参数-x同时使用。如果命令中指定了设备名称,显示设备和它的所有分区的统计。如果使用了关键字ALL,将显示系统所有块设备和分区统计信息,即使它们没有被使用。只有在内核2.5或更新版本中有效。 |
interval | 刷新时间间隔 |
count | 刷新次数 |
CPU统计信息字段说明
参数 | 描述 |
---|---|
%user | Show the percentage of CPU utilization that occurred while executing at the user level (application). 用户进程使用的CPU使用率百分比。 |
%nice | Show the percentage of CPU utilization that occurred while executing at the user level with nice priority. |
%system | Show the percentage of CPU utilization that occurred while executing at the system level (kernel). 系统进程使用的CPU使用率百分比。 |
%iowait | Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request. 系统输出数据至磁盘时空闲的CPU时间百分比(即IO等待)。 |
%steal | Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servic-ing another virtual processor. |
%idle | Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request. 系统没有任何数据输出至磁盘的CPU时间百分比(即空闲时间) |
设备统计信息字段说明
参数 | 描述 |
---|---|
Device | This column gives the device (or partition) name, which is displayed as hdiskn with 2.2 kernels, for the nth device. It is displayed as devm-n with 2.4 kernels, where m is the major number of the device, and n a distinc-tive number. With newer kernels, the device name as listed in the /dev directory is displayed. 设备或分区名称。 |
tps | Indicate the number of transfers per second that were issued to the device. A transfer is an I/O request to the device. Multiple logical requests can be combined into a single I/O request to the device. A transfer is of inde-terminate size. 设备每秒的传输次数。一个IO请求表示一个传输。多个逻辑请求可以被组成一个I/O请求。一个传输的大小未知。 |
Blk_read/s | Indicate the amount of data read from the device expressed in a number of blocks per second. Blocks are equiva-lent to sectors with 2.4 kernels and newer and therefore have a size of 512 bytes. With older kernels, a block is of indeterminate size. 每秒从设备读取数据量(单位:数据块)。 |
Blk_wrtn/s | Indicate the amount of data written to the device expressed in a number of blocks per second. 每秒写入设备的数据量(单位:数据块)。 |
Blk_read | The total number of blocks read. 读取的总数量(单位:数据块)。 |
Blk_wrtn | The total number of blocks written. 写入的总数量(单位:数据块)。 |
kB_read/s | Indicate the amount of data read from the device expressed in kilobytes per second. 每秒从设备读取的数据量(单位:KB) |
kB_wrtn/s | Indicate the amount of data written to the device expressed in kilobytes per second. 每秒写入设备的数据量(单位:KB) |
kB_read | The total number of kilobytes read. 读取的总数量(单位:KB) |
kB_wrtn | The total number of kilobytes written. 写入的总数量(单位:KB)。 |
MB_read/s | Indicate the amount of data read from the device expressed in megabytes per second. 每秒从设备读取的数据量(单位:MB) |
MB_wrtn/s | Indicate the amount of data written to the device expressed in megabytes per second. 每秒写入设备的数据量(单位:MB) |
MB_read | The total number of megabytes read. 读取的总数量(单位:MB) |
MB_wrtn | The total number of megabytes written. 写入的总数量(单位:MB)。 |
rrqm/s | The number of read requests merged per second that were queued to the device. 每秒被合并的读请求数。 |
wrqm/s | The number of write requests merged per second that were queued to the device. 每秒被合并的写请求数。 |
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. 每秒从设备读取的数据量(单位:KB) |
wkB/s | The number of kilobytes written to the device per second. 每秒写入设备的数据量(单位:KB) |
rMB/s | The number of megabytes read from the device per second. 每秒从设备读取的数据量(单位:MB) |
wMB/s | The number of megabytes written to the device per second. 每秒写入设备的数据量(单位:MB) |
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. I/O请求等待时间的平均值(单位:毫秒)。 |
svctm | The average service time (in milliseconds) for I/O requests that were issued to the device. I/O请求处理时间的平均值(单位:毫秒)。 |
%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%. 消耗在I/O请求中的CPU时间百分比(设备带宽利用率)。如果该值接近100%说明设备出现了瓶颈。 |
示例
1、统计CPU使用情况
iostat -c 1 3
2、统计磁盘使用情况
iostat -d 1 3
转自 http://www.orczhou.com/index.php/2010/03/iostat-detail/