Linux性能分析之iostat命令

  • iostat是I/O statistics(输入/输出统计)的缩写,iostat工具将对系统的磁盘操作活动进行监视。汇报磁盘活动统计情况,同时也会汇报出CPU使用情况,统计整体情况,无法查看单个进程
  • 磁盘性能观测的主要指标:

  1. 使用率(%util)
  2. 吞吐量(rMB/s,wMB/s)
  3. 响应时间(r_awaite,w_await)
  4. IOPS(r/s,w/s)
  5. 饱和度
  • iostat命令输出

#刷新频率2
$iostat -d 2
Linux 3.10.0-693.el7.x86_64 (test) 	06/04/2019 	_x86_64_	(32 CPU)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               2.17         6.75       275.30     660279   26927471
dm-0              0.38         4.43         0.37     432940      36249
dm-1              0.00         0.03         0.00       3412          0
dm-2              1.04         0.05       265.37       5307   25956632
dm-3              0.25         0.31         3.07      30225     300405
dm-4              0.54         1.74         6.25     169888     611692
sdb               0.00         0.01         0.00       1072          0
sdc               0.00         0.01         0.00       1072          0
#刷新次数2
$iostat -d 2 2
Linux 3.10.0-693.el7.x86_64 (test) 	06/04/2019 	_x86_64_	(32 CPU)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               2.17         6.75       275.11     660279   26928402
dm-0              0.38         4.42         0.37     432940      36249
dm-1              0.00         0.03         0.00       3412          0
dm-2              1.04         0.05       265.18       5307   25956632
dm-3              0.25         0.31         3.07      30225     300449
dm-4              0.54         1.74         6.26     169888     612579
sdb               0.00         0.01         0.00       1072          0
sdc               0.00         0.01         0.00       1072          0

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               0.00         0.00         0.00          0          0
dm-0              0.00         0.00         0.00          0          0
dm-1              0.00         0.00         0.00          0          0
dm-2              0.00         0.00         0.00          0          0
dm-3              0.00         0.00         0.00          0          0
dm-4              0.00         0.00         0.00          0          0
sdb               0.00         0.00         0.00          0          0
sdc               0.00         0.00         0.00          0          0

(everest-dev-env) 
#指定要显示的设备
$iostat -x sda 2 2
Linux 3.10.0-693.el7.x86_64 (test) 	06/04/2019 	_x86_64_	(32 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.17    0.00    0.04    0.01    0.00   99.78

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00     0.06    0.42    1.74     6.74   275.00   260.18     0.01    3.32    6.25    2.61   0.40   0.09

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    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_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   0.00   0.00

(everest-dev-env) 

$iostat -p sda 2 2
Linux 3.10.0-693.el7.x86_64 (test) 	06/04/2019 	_x86_64_	(32 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.17    0.00    0.04    0.01    0.00   99.78

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               2.16         6.74       274.87     660279   26928688
sda1              0.00         0.02         0.00       2176          0
sda2              0.01         0.13         0.23      12758      22492
sda3              2.15         6.58       274.64     644293   26906196

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.08    0.00    0.02    0.02    0.00   99.89

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_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

(everest-dev-env) 

#以MB/s为单位
[root@test /root]
$iostat -xm 5
Linux 3.10.0-693.el7.x86_64 (test) 	06/04/2019 	_x86_64_	(32 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.17    0.00    0.04    0.01    0.00   99.77

Device:         rrqm/s   wrqm/s     r/s     w/s    rMB/s    wMB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda               0.00     0.07    0.48    1.88     0.01     0.30   268.04     0.01    3.43    6.25    2.72   0.41   0.10
dm-0              0.00     0.00    0.41    0.02     0.00     0.00    25.04     0.00    4.74    4.96    0.43   1.72   0.07
dm-1              0.00     0.00    0.00    0.00     0.00     0.00    62.61     0.00    7.58    7.58    0.00   7.04   0.00
dm-2              0.00     0.00    0.00    1.17     0.00     0.29   509.18     0.01    4.35    9.91    4.34   0.05   0.01
dm-3              0.00     0.00    0.01    0.24     0.00     0.00    29.10     0.00    0.29    3.92    0.07   0.15   0.00
dm-4              0.00     0.00    0.04    0.51     0.00     0.01    29.67     0.00    1.58   19.39    0.06   0.37   0.02
sdb               0.00     0.00    0.00    0.00     0.00     0.00    41.23     0.00    0.13    0.13    0.00   0.13   0.00
sdc               0.00     0.00    0.00    0.00     0.00     0.00    41.23     0.00    0.13    0.13    0.00   0.12   0.00

  • 各个参数含义:

%user: 在用户级别运行所使用的CPU的百分比.
%nice: nice操作所使用的CPU的百分比.
%sys: 在系统级别(kernel)运行所使用CPU的百分比.
%iowait: CPU等待硬件I/O时,所占用CPU百分比.
%idle: CPU空闲时间的百分比.
tps: 每秒钟发送到的I/O请求数.
Blk_read /s: 每秒读取的block数.
Blk_wrtn/s: 每秒写入的block数.
Blk_read:   读入的block总数.
Blk_wrtn:  写入的block总数.
Blk_read:读入块的当总数.

rrqm/s:将读入请求合并后,每秒发送到设备的读入请求数.
wrqm/s:将写入请求合并后,每秒发送到设备的写入请求数.
r/s:每秒发送到设备的读入请求数.
w/s:每秒发送到设备的写入请求数.
rsec/s:每秒从设备读入的扇区数.
wsec/s:每秒向设备写入的扇区数.
rkB/s:每秒从设备读入的数据量,单位为K.
wkB/s:每秒向设备写入的数据量,单位为K.
avgrq-sz:发送到设备的请求的平均大小,单位是扇区.
avgqu-sz:发送到设备的请求的平均队列长度.
await:I/O请求平均执行时间.包括发送请求和执行的时间.单位是毫秒.
svctm:发送到设备的I/O请求的平均执行时间.单位是毫秒.
%util:采用周期内用于IO操作的时间比率,即IO队列非空的时间比率

注:

饱和度:无法从iostat直接查看(平均请求队列长度或者读写请求完成的等待时间,跟基准测试的结果(比如通过 fio)进行对比,综合评估磁盘的饱和情况)

wait的时间:执行时间+等待时间

单位:请求数往往以块为单位,时间往往以毫秒为单位



man iostat:

IOSTAT(1)                                    Linux User's Manual                                    IOSTAT(1)



NAME
       iostat  -  Report Central Processing Unit (CPU) statistics and input/output statistics for devices and
       partitions.

SYNOPSIS
       iostat [ -c ] [ -d ] [ -h ] [ -k | -m ] [ -N ] [ -t ] [ -V ] [ -x ] [ -y ] [ -z ] [ -j { ID | LABEL  |
       PATH | UUID | ... } ] [ [ -T ] -g group_name ] [ -p [ device [,...] | ALL ] ] [ 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 physi?
       cal disks.

       The  first  report  generated  by the iostat command provides statistics concerning the time since the
       system was booted, unless the -y option is used (in this case, this first report  is  omitted).   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 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 configured.

       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), unless the -y option is used (in this
       case, this report is omitted).  Each subsequent report contains statistics collected during the inter?
       val  since  the previous report. The count parameter can be specified in conjunction with the interval
       parameter. If the count parameter is specified, the value of count determines the  number  of  reports
       generated  at interval seconds apart. If the interval parameter is specified without the count parame?
       ter, the iostat command generates reports continuously.


REPORTS
       The iostat command generates two types of reports, the CPU Utilization report and the Device  Utiliza?
       tion report.

       CPU Utilization Report
              The  first  report generated by the iostat command is the CPU Utilization Report. For multipro?
              cessor systems, the CPU values are global averages among all processors.  The  report  has  the
              following format:

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

              %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).

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

              %steal
                     Show  the  percentage of time spent in involuntary wait by the virtual CPU or CPUs while
                     the hypervisor was servicing 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.

       Device Utilization Report
              The  second report generated by the iostat command is the Device Utilization Report. The device
              report provides statistics on a per physical device or partition basis. Block devices and  par?
              titions  for  which  statistics  are to be displayed may be entered on the command line.  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.  Transfer rates are shown in 1K blocks by default,
              unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
              The report may show the following fields, depending on the flags used:

              Device:
                     This column gives the device (or partition) name as listed in the /dev directory.

              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 (kB_read/s, MB_read/s)
                     Indicate  the amount of data read from the device expressed in a number of blocks (kilo?
                     bytes, megabytes) per second. Blocks are equivalent to sectors and therefore have a size
                     of 512 bytes.

              Blk_wrtn/s (kB_wrtn/s, MB_wrtn/s)
                     Indicate the amount of data written to the device expressed in a number of blocks (kilo?
                     bytes, megabytes) per second.

              Blk_read (kB_read, MB_read)
                     The total number of blocks (kilobytes, megabytes) read.

              Blk_wrtn (kB_wrtn, MB_wrtn)
                     The total number of blocks (kilobytes, 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 (after merges) of read requests completed per second for the device.

              w/s
                     The number (after merges) of write requests completed per second for the device.

              rsec/s (rkB/s, rMB/s)
                     The number of sectors (kilobytes, megabytes) read from the device per second.

              wsec/s (wkB/s, wMB/s)
                     The number of sectors (kilobytes, 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.

              r_await
                     The  average time (in milliseconds) for read requests issued to the device to be served.
                     This includes the time spent by the requests in queue and the time spent servicing them.

              w_await
                     The average time (in milliseconds) for write 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  elapsed  time during which I/O requests were issued to the device (band?
                     width utilization for the device). Device saturation occurs when this value is close  to
                     100%.

OPTIONS
       -c     Display the CPU utilization report.

       -d     Display the device utilization report.

       -g group_name { device [...] | ALL }
              Display  statistics  for  a  group  of devices.  The iostat command reports statistics for each
              individual device in the list then a line of global  statistics  for  the  group  displayed  as
              group_name and made up of all the devices in the list. The ALL keyword means that all the block
              devices defined by the system shall be included in the group.

       -h     Make the Device Utilization Report easier to read by a human.

       -j { ID | LABEL | PATH | UUID | ... } [ device [...] | ALL ]
              Display persistent device names. Options ID, LABEL, etc. specify the  type  of  the  persistent
              name.  These options are not limited, only prerequisite is that directory with required persis?
              tent names is present in /dev/disk.  Optionally, multiple devices can be specified in the  cho?
              sen  persistent  name  type.   Because  persistent  device names are usually long, option -h is
              enabled implicitly with this option.

       -k     Display statistics in kilobytes per second.

       -m     Display statistics in megabytes per second.

       -N     Display the registered device mapper names for any device mapper devices.  Useful  for  viewing
              LVM2 statistics.

       -p [ { device [,...] | ALL } ]
              The  -p  option 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 dis?
              played for all the block devices and partitions defined by the  system,  including  those  that
              have  never  been used. If option -j is defined before this option, devices entered on the com?
              mand line can be specified with the chosen persistent name type.

       -T     This option must be used with option -g and indicates that only global statistics for the group
              are to be displayed, and not statistics for individual devices in the group.

       -t     Print  the  time for each report displayed. The timestamp format may depend on the value of the
              S_TIME_FORMAT environment variable (see below).

       -V     Print version number then exit.

       -x     Display extended statistics.

       -y     Omit first report with statistics since system boot, if displaying multiple  records  at  given
              interval.

       -z     Tell  iostat  to  omit output for any devices for which there was no activity during the sample
              period.


ENVIRONMENT
       The iostat command takes into account the following environment variables:


       S_TIME_FORMAT
              If this variable exists and its value is ISO then the  current  locale  will  be  ignored  when
              printing  the date in the report header. The iostat command will use the ISO 8601 format (YYYY-
              MM-DD) instead.  The timestamp displayed with option -t will also be compliant  with  ISO  8601
              format.


       POSIXLY_CORRECT
              When  this  variable is set, transfer rates are shown in 512-byte blocks instead of the default
              1K blocks.


EXAMPLES
       iostat
              Display a single history since boot report for all CPU and Devices.

       iostat -d 2
              Display a continuous device report at two second intervals.

       iostat -d 2 6
              Display six reports at two second intervals for all devices.

       iostat -x sda sdb 2 6
              Display six reports of extended statistics at two second intervals for devices sda and sdb.

       iostat -p sda 2 6
              Display six reports at two second intervals for device sda and all its partitions (sda1, etc.)

BUGS
       /proc filesystem must be mounted for iostat to work.

       Kernels older than 2.6.x are no longer supported.

       The average service time (svctm field) value is meaningless, as I/O statistics are now  calculated  at
       block level, and we don't know when the disk driver starts to process a request. For this reason, this
       field will be removed in a future sysstat version.

FILES
       /proc/stat contains system statistics.

       /proc/uptime contains system uptime.

       /proc/diskstats contains disks statistics.

       /sys contains statistics for block devices.

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

       /dev/disk contains persistent device names.

AUTHOR
       Sebastien Godard (sysstat  orange.fr)

SEE ALSO
       sar(1), pidstat(1), mpstat(1), vmstat(8), nfsiostat(1), cifsiostat(1)

       http://pagesperso-orange.fr/sebastien.godard/



Linux                                           NOVEMBER 2012                                       IOSTAT(1)

 

你可能感兴趣的:(Linux)