linux 中的iostat命令监控IO

1.实验环境
     
     
     
     
[root@Server ~]# more /etc/issue
Red Hat Enterprise Linux Server release 6.4 (Santiago)
Kernel \r on an \m


2.iostat命令说明
     
     
     
     
NAME
iostat - Report Central Processing Unit (CPU) statistics and input/output
statistics for devices, partitions and network filesystems (NFS).
 
SYNOPSIS
iostat [ -c ] [ -d ] [ -N ] [ -n ] [ -h ] [ -k | -m ] [ -t ] [ -V ] [ -x ] [
-z ] [ device [...] | ALL ] [ -p [ device [,...] | ALL ] ] [ interval [
count ] ]
 
DESCRIPTION
The iostat command is used for monitoring system input/output device loading
by observing the time the devices are active in relation to their average
transfer rates. The iostat command generates reports that can be used to
change system configuration to better balance the input/output load between
physical disks.
 
The first report generated by the iostat command provides statistics con-
cerning the time since the system was booted. Each subsequent report covers
the time since the previous report. All statistics are reported each time
the iostat command is run. The report consists of a CPU header row followed
by a row of CPU statistics. On multiprocessor systems, CPU statistics are
by a row of CPU statistics. On multiprocessor systems, CPU statistics are
calculated system-wide as averages among all processors. A device header row
is displayed followed by a line of statistics for each device that is con-
figured. When option -n is used, an NFS header row is displayed followed by
a line of statistics for each network filesystem that is mounted.
 
The interval parameter specifies the amount of time in seconds between each
report. The first report contains statistics for the time since system
startup (boot). Each subsequent report contains statistics collected during
the interval since the previous report. The count parameter can be specified
in conjunction with the interval parameter. If the count parameter is speci-
fied, the value of count determines the number of reports generated at
interval seconds apart. If the interval parameter is specified without the
count parameter, the iostat command generates reports continuously.

3.主要参数
-c     Display the CPU utilization report.(显示CPU使用报告)
-d     Display the device utilization report.(显示设备IO使用报告)
-n     Display the network filesystem (NFS) report. This option  works  only
              with kernel 2.6.17 and later.(显示网络文件系统NFS的使用报告)
例如,监控IO使用:
iostat -d 1 10
1是指每隔1秒生成一次报告,10代表报告10次
     
     
     
     
[root@Server ~]# iostat -d 1 10
Linux 2.6.32-358.el6.x86_64 (Server.example.com) 09/23/2015 _x86_64_ (2 CPU)
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 1.70 78.87 3.05 175356 6786
scd0 0.03 0.32 0.00 712 0
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
scd0 0.00 0.00 0.00 0 0
第一个 iostat 命令报告显示的是从启用磁盘输入/输出统计信息那一刻时间间隔起点起的行为,没有实际意义,第二个开始是上次的增量统计


-p  显示磁盘上的分区IO信息
     
     
     
     
[root@Server dev]# iostat -p sda 1 4
Linux 2.6.32-358.el6.x86_64 (Server.example.com) 09/23/2015 _x86_64_ (2 CPU)
 
avg-cpu: %user %nice %system %iowait %steal %idle
0.05 0.00 0.27 0.21 0.00 99.47
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 1.30 58.92 2.62 175364 7810
sda1 0.20 1.56 0.01 4634 18
sda2 0.11 0.98 0.00 2904 0
sda3 0.94 55.98 2.62 166610 7792
 
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.00 0.00 100.00
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
sda1 0.00 0.00 0.00 0 0
sda2 0.00 0.00 0.00 0 0
sda3 0.00 0.00 0.00 0 0
 
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.00 0.00 100.00
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
sda1 0.00 0.00 0.00 0 0
sda2 0.00 0.00 0.00 0 0
sda3 0.00 0.00 0.00 0 0
 
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.50 0.00 0.00 99.50
 
Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
sda 0.00 0.00 0.00 0 0
sda1 0.00 0.00 0.00 0 0
sda2 0.00 0.00 0.00 0 0
sda3 0.00 0.00 0.00 0 0

-x  显示基本统计信息外的额外信息(需要按KB或者MB输出r/s的话加参数 -k  /  -m)
     
     
     
     
[root@Server dev]# iostat -p sda -x 1 4
Linux 2.6.32-358.el6.x86_64 (Server.example.com) 09/23/2015 _x86_64_ (2 CPU)
 
avg-cpu: %user %nice %system %iowait %steal %idle
0.05 0.00 0.27 0.20 0.00 99.48
 
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
sda 0.88 0.16 1.10 0.17 57.31 2.64 47.30 0.02 16.34 3.20 0.41
sda1 0.08 0.00 0.19 0.00 1.51 0.01 7.93 0.00 0.58 0.57 0.01
sda2 0.01 0.00 0.11 0.00 0.95 0.00 8.75 0.00 1.28 1.28 0.01
sda3 0.79 0.16 0.75 0.17 54.45 2.63 62.23 0.02 22.22 4.30 0.39
 
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.50 0.00 0.00 99.50
 
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz 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
sda1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda3 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 0.00 0.00 0.00 100.00
 
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz 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
sda1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda3 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 0.00 0.00 0.00 100.00
 
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz 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
sda1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
sda3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00



4.统计指标的含义
     
     
     
     
Device Utilization Report
The second report generated by the iostat command is the Device Uti-
lization Report. The device report provides statistics on a per phys-
ical device or partition basis. Block devices for which statistics
are to be displayed may be entered on the command line. Partitions
may also be entered on the command line providing that option -x is
not used. If no device nor partition is entered, then statistics are
displayed for every device used by the system, and providing that the
kernel maintains statistics for it. If the ALL keyword is given on
the command line, then statistics are displayed for every device
defined by the system, including those that have never been used.
The report may show the following fields, depending on the flags
used:
 
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 distinctive 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 indeterminate size.
 
Blk_read/s
Indicate the amount of data read from the device expressed in
a number of blocks per second. Blocks are equivalent to sec-
tors with kernels 2.4 and later 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_wrtn/s
Indicate the amount of data written to the device expressed in
kilobytes per second.
 
kB_read
The total number of kilobytes read.
 
kB_wrtn
The total number of kilobytes written.
 
MB_read/s
Indicate the amount of data read from the device expressed in
megabytes per second.
 
MB_wrtn/s
Indicate the amount of data written to the device expressed in
megabytes per second.
 
MB_read
The total number of megabytes read.
 
MB_wrtn
The total number of megabytes written.
 
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.
 
wkB/s
The number of kilobytes written to the device per second.
 
rMB/s
The number of megabytes read from the device per second.
 
wMB/s
The number of megabytes 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.
 
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.
 
%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%.

5.实用脚本

监控iostat的数据并按 %util   排序
ksh版,这个照抄《Oracle Database 11g 性能调整与优化》 一书上的案例
     
     
     
     
iostat -x | awk '/^disk/'
iostat -x 5 5 | grep -v '^ ' | grep -v '^disk' | awk '{
print $10 ", " $0
}' $* |
sort -n |
awk -F, '{
print $2
}' |
tail


bash下的改进版
iostat -x | awk '/^Device/'
iostat -x 1 2| grep -v '^ ' | grep -v '/^Device/' | awk '{ print $12  ", "  $0 }'| sort -rn | grep ^[0-9] | awk -F,  '{print $2}'

改进版V1.1 删除第一次的iostat报告,因为第一次的iostat报告是不能用的
[ ! $# -eq 2 ]  && echo "Usage: iomonitor interval count" && exit 1
[ ! $1 -gt 0 ]  && echo " interval  must greater than 0 " && exit 1
[ ! $2 -gt 0 ]  && echo " count  must greater than 0 " && exit 1
dline=`iostat -x | wc -l`
iostat -x | awk '/^Device/'
iostat -x $1  $2 |sed '1,'$dline'd'| grep -v '^ ' | grep -v '/^Device/' | 
awk '{ print $12  ", "  $0 }'| sort -rn | grep ^[0-9] | awk -F,  '{print $2}'













你可能感兴趣的:(Linux)