Linux系统监控:iostat

简介

      对于有磁盘操作的应用来说,查找性能问题,就应监控磁盘I/O。其中磁盘I/O使用率是最有用的监控数据。磁盘I/O使用率,即磁盘处于活动时间的百分比,磁盘在数据传输和处理命令(如寻道)时处于活动状态。磁盘利用率与资源争用程度成正比,与性能成反比。也就是说磁盘利用率越高,资源争用就越严重,性能也就越差,响应时间就越长。一般来说,如果磁盘利用率超过 70%,应用进程将花费较长的时间等待 I/O 完成,因为绝大多数进程在等待过程中将被阻塞或休眠。

语法

       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 ] ]

描述

       iostat命令用来监控系统的I/O设备负载,通过监视设备处于活动状态的时间,而不是它们的平均传输速率。iostat产生的报告可以用来协助修改系统配置,以在物理磁盘之间达到更好的I/O负载均衡。

       iostat命令产生的第一条报告给出自系统启动以来的设备处于活动状态的时间,除非显示的指定了-y选项(这种情况下,第一行会被忽略)。接下来的报告是自上一次报告以来的时间。iostat

命令每运行一次产生一条全量统计报告。报告包含一个CPU行以及若干行CPU统计数据。在多处理器系统中,CPU统计数据是所有处理器的平均值。接下来的一行是设备头,以及每个设备的统计数据。

       interval参数指定每次报告的间隔,以秒为单位。count参数可以在指定了interval后指定,该参数决定产生报告的次数。如果指定了interval参数后没有指定count参数,iostat命令会一直产生报告。

报告

       iostat命令产生两种类型的报告,CPU利用率报告和设备利用率报告。

       CPU利用率报告

              iostat命令产生的第一个报告是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.

                     以nice优先级执行的用户态(应用)的CPU利用率

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

                     系统有未处理的磁盘I/O请求造成的CPU(s)空闲的时间比例。

              %steal

                     Show  the  percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another

                     virtual processor.

                     虚拟CPU(s)由于hypervisor正在服务其他虚拟处理器的被迫等待时间。

                     Hypervisor——一种运行在基础物理服务器和操作系统之间的中间软件层,可允许多个操作系统和应用共享硬件。也可叫做VMM( virtual machine monitor ),即虚拟机监视器。

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

                     系统没有未处理的磁盘I/O请求,且CPU(s)空闲的时间比例。

设备利用率报告

              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 partitions for which statistics are to be displayed may be entered on the com‐

              mand 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:

              iostat命令产生的第二个报告是设备利用率报告。设备报告提供每个物理设备或分区的统计数据。

              Device:

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

                     显示/dev目录中列出的设备(或分区)名称。

              tps

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

                     tiple logical requests can be combined into a single I/O request to the device. A transfer is of indeterminate size.

                     指示该设备每秒的传输次数。一次传输是该设备的一次I/O请求,多个逻辑请求可以合并成一个单独的I/O请求。一次传输的大小是不确定的。

              Blk_read/s (kB_read/s, MB_read/s)

                     Indicate  the  amount  of data read from the device expressed in a number of blocks (kilobytes, megabytes) per second. Blocks

                     are equivalent to sectors and therefore have a size of 512 bytes.

                     指示每秒从该设备读取的数据总量,以块为单位。块和扇区相等,因此是512bytes。

              Blk_wrtn/s (kB_wrtn/s, MB_wrtn/s)

                     Indicate the amount of data written to the device expressed in a number of blocks (kilobytes, megabytes) per second.

                     指示每秒写入该设备的数据总量,以块为单位。块和扇区相等,因此是512bytes。

              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.

                     该设备的I/O请求的平均处理时间(以毫秒为单位)。包括花费在队列以及处理的时间。

              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 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% for devices serving requests serially.  But for devices serving requests

                     in parallel, such as RAID arrays and modern SSDs, this number does not reflect their performance limits.

                     设备处于活动状态的时间的百分比(该设备的带宽利用率)。当该值接近100%时,设备接近饱和。但对于并行处理请求的设备,如RAID磁盘阵列、SSD,该值并不能反映他们的性能状态。

                     

OPTIONS

       -c     Display the CPU utilization report.

              显示CPU利用率报告。

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

              显示一组设备的统计数据。示例:iostat -h -g mygroup {sda,dm-0} 或者iostat -h -g mygroup sda dm-0

       -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 persistent names is present in /dev/disk.  Optionally, multiple devices can be

              specified in the chosen 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.

              以kb/s为单位展示统计数据

       -m     Display statistics in megabytes per second.

              以mb/s为单位展示统计数据

       -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  sta‐

              tistics  have  to  be displayed 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 command 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 statis‐

              tics for individual devices in the group.

              该选项必须和-g选项一起使用,用来指定只显示全局统计数据。

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

              显示扩展的统计信息。指定此选项来查看磁盘I/O利用率

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

相关推荐