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

來源:互聯網
上載者:User

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

我們可以使用 sar(1), pidstat(1), mpstat(1), vmstat(8) 來監控

一、安裝
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 4Linux 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_wrtnxvda            114.22        13.80       713.21  372234513 19241775188xvdb             19.26        21.24       144.25  573067009 3891812336Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtnxvda              0.00         0.00         0.00          0          0xvdb              4.50         0.00        18.00          0         36Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtnxvda              0.00         0.00         0.00          0          0xvdb             10.50         0.00        42.00          0         84Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtnxvda              0.00         0.00         0.00          0          0xvdb             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 10Linux 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  %utilxvda              0.02     0.69    0.56  113.65    13.80   713.21    12.73     0.00    0.03   0.48   5.53xvdb              0.02    17.88    1.07   18.19    21.24   144.27    17.19     0.13    6.71   1.69   3.25Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %utilxvda              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00xvdb              0.00     0.00    0.00    5.00     0.00    20.00     8.00     0.11   22.00   4.40   2.20Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await  svctm  %utilxvda              0.00     0.00    0.00    0.00     0.00     0.00     0.00     0.00    0.00   0.00   0.00xvdb              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 10Linux 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.55avg-cpu:  %user   %nice %system %iowait  %steal   %idle           1.75    0.00    0.50    0.00    0.00   97.75avg-cpu:  %user   %nice %system %iowait  %steal   %idle           1.50    0.00    0.50    0.00    0.00   98.00avg-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狀態

 

參考文章

http://www.cnblogs.com/peida/archive/2012/12/28/2837345.html

http://www.mjmwired.net/kernel/Documentation/iostats.txt

http://www.orczhou.com/index.php/2010/03/iostat-detail/

http://www.php-oa.com/2009/02/03/iostat.html

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.