歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux下使用iostat 監視I/O狀態

Linux下使用iostat 監視I/O狀態

日期:2017/2/28 13:54:54   编辑:Linux教程

Linux下我們可以使用 sar(1), pidstat(1), mpstat(1), vmstat(8) 來監控I/O狀態

一、安裝

yum install sysstat

二、參數解釋

FILES

/proc/stat contains system statistics.

/proc/uptime contains system uptime.

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

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

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

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

/dev/disk contains persistent device names.

CPU Utilization Report 

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

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

%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 outstand-ing disk I/O request.

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

%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 Utilization Report

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

Network Filesystem report

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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

命令參數

-C 顯示CPU使用情況

-d 顯示磁盤使用情況

-k 以 KB 為單位顯示

-m 以 M 為單位顯示

-N 顯示磁盤陣列(LVM) 信息

-n 顯示NFS 使用情況

-p[磁盤] 顯示磁盤和分區的情況

-t 顯示終端和CPU的信息

-x 顯示詳細信息

-V 顯示版本信息


三、使用方式

Device Utilization Report

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

Linux 2.6.32-431.11.2.el6.x86_64 (localhost) 01/08/2016 _x86_64_ (4 CPU)

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn

xvda 114.22 13.80 713.21 372234513 19241775188

xvdb 19.26 21.24 144.25 573067009 3891812336

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn

xvda 0.00 0.00 0.00 0 0

xvdb 4.50 0.00 18.00 0 36

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn

xvda 0.00 0.00 0.00 0 0

xvdb 10.50 0.00 42.00 0 84

Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn

xvda 0.00 0.00 0.00 0 0

xvdb 20.50 0.00 86.00 0 172

參數說明

  • tps:該設備每秒的傳輸次數,多個邏輯請求可以組合成一個單一的 I/O 請求的設備。傳輸具有不確定的大小。
  • kB_read/s:每秒從設備讀取的數據量
  • kB_wrtn/s:每秒向設備寫入的數據量
  • kB_read:讀取的總數據量
  • kB_wrtn:寫入的總數量數據量

[root@localhost ~]# iostat -d -x -k 1 10

Linux 2.6.32-431.11.2.el6.x86_64 (localhost) 01/08/2016 _x86_64_ (4 CPU)

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

xvda 0.02 0.69 0.56 113.65 13.80 713.21 12.73 0.00 0.03 0.48 5.53

xvdb 0.02 17.88 1.07 18.19 21.24 144.27 17.19 0.13 6.71 1.69 3.25

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

xvda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

xvdb 0.00 0.00 0.00 5.00 0.00 20.00 8.00 0.11 22.00 4.40 2.20

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

xvda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

xvdb 0.00 0.00 0.00 16.00 0.00 64.00 8.00 0.80 50.19 6.81 10.90

總IO(io)/s = r/s(讀) +w/s(寫)

平均等待時間 = 單個 I/O 服務時間 * ( 1 + 2 + … + 請求總數-1) / 請求總數

參數說明

  • rrqm/s:每秒進行 merge 的讀操作數目.即 delta(rmerge)/s
  • wrqm/s:每秒進行 merge 的寫操作數目.即 delta(wmerge)/s
  • r/s:每秒完成的讀 I/O 設備次數.即 delta(rio)/s
  • w/s:每秒完成的寫 I/O 設備次數.即 delta(wio)/s
  • rsec/s:每秒讀扇區數.即 delta(rsect)/s
  • wsec/s:每秒寫扇區數.即 delta(wsect)/s
  • rkB/s:每秒讀K字節數.是 rsect/s 的一半,因為每扇區大小為512字節.(需要計算)
  • wkB/s:每秒寫K字節數.是 wsect/s 的一半.(需要計算)
  • avgrq-sz: 平均每次設備I/O操作的數據大小 (扇區).delta(rsect+wsect)/delta(rio+wio)
  • avgqu-sz: 平均I/O隊列長度.即 delta(aveq)/s/1000 (因為aveq的單位為毫秒).
  • await:平均每次設備I/O操作的等待時間 (毫秒).即 delta(ruse+wuse)/delta(rio+wio)
  • svctm:平均每次設備I/O操作的服務時間 (毫秒).即 delta(use)/delta(rio+wio)
  • %util:一秒中有百分之多少的時間用於 I/O 操作,或者說一秒中有多少時間 I/O 隊列是非空的.即 delta(use)/s/1000 (因為use的單位為毫秒)

如果%util 接近 100%,說明產生的I/O請求太多,I/O系統已經滿負荷,該磁盤可能存在瓶頸.
如果idle小於70% IO壓力就較大了,一般讀取速度有較多的wait

avgqu-sz 是需要注意的地方,這個就是直接每次操作的數據的大小,如果次數多,但數據小的話,其實 IO 也會很小.如果數據大,才IO 的數據會高,通過 avgqu-sz × ( r/s or w/s ) = rsec/s or wsec/s

CPU Utilization Report 

[root@localhost ~]# iostat -c 1 10

Linux 2.6.32-431.11.2.el6.x86_64 (localhost) 01/08/2016 _x86_64_ (4 CPU)

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

5.09 0.00 2.08 4.28 0.00 88.55

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

1.75 0.00 0.50 0.00 0.00 97.75

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

1.50 0.00 0.50 0.00 0.00 98.00

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

0.25 0.00 0.25 0.00 0.00 99.50


參數說明

  • %user:CPU處在用戶模式下的時間百分比
  • %nice:CPU處在帶NICE值的用戶模式下的時間百分比
  • %system:CPU處在系統模式下的時間百分比
  • %iowait:CPU等待輸入輸出完成時間的百分比
  • %steal:管理程序維護另一個虛擬處理器時,虛擬CPU的無意識等待時間百分比
  • %idle:CPU空閒時間百分比

如果%iowait的值過高,表示硬盤存在I/O瓶頸,%idle值高,表示CPU較空閒

如果%idle值高但系統響應慢時,有可能是CPU等待分配內存,此時應加大內存容量,%idle值如果持續低於10,那麼系統的CPU處理能力相對較低,表明系統中最需要解決的資源是CPU

常見用法

iostat -d -k 1 10 #查看TPS和吞吐量信息

iostat -d -x -k 1 10 #查看設備使用率(%util)、響應時間(await)

iostat -c 1 10 #查看cpu狀態

RH442攻略之iostat http://www.linuxidc.com/Linux/2014-03/98254.htm

Linux 下使用iostat命令生成CPU和I/O的統計報告 http://www.linuxidc.com/Linux/2014-02/96689.htm

安裝iostat和mpstat工具 http://www.linuxidc.com/Linux/2013-10/91570.htm

Linux iostat命令輸出簡要說明 http://www.linuxidc.com/Linux/2013-06/86703.htm

Linux iostat命令 http://www.linuxidc.com/Linux/2013-03/80163.htm

Linux iostat命令實例詳解 http://www.linuxidc.com/Linux/2014-07/104151.htm

iostat命令詳解 http://www.linuxidc.com/Linux/2015-03/114455.htm

Copyright © Linux教程網 All Rights Reserved