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

来源:http://www.cnblogs.com/chenpingzhao/archive/2016/01/08/5115063.html
-Advertisement-
Play Games

我們可以使用sar(1), pidstat(1), mpstat(1), vmstat(8) 來監控一、安裝yum install sysstat二、參數解釋FILES/proc/stat contains system statistics./proc/uptime contains system...


我們可以使用 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 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狀態

 

參考文章

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

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • Python keyword 模塊的學習筆記
  • Work發佈博客測試文件 一段java代碼 //1到30數隨機里取7個 public static void main(String[] args) { for (int i = 0; i 測試專用jsp 一些sql代...
  • JQuery選擇器從大的角度分為jQuery 基礎選擇器、jQuery過濾性選擇器、jQuery表單選擇器。
  • 在Mac OS X上安裝 Ruby運行環境 對於新入門的開發者,如何安裝 Ruby和Ruby Gems 的運行環境可能會是個問題,本頁主要介紹如何用一條靠譜的路子快速安裝 Ruby 開發環境。此安裝方法同樣適用於產品環境!系統需求首先確定操作系統環境,不建議在 Windows 上面搞,所以你需要用....
  • 從以下5個方面學習hibernate ORM。(1)配置文件:hibernate.cfg.xml XML文件和hibernate.properties屬性文件(2)實體映射:1對多、多對多(3)會話工廠與會話:SessionFactory&Session(4)查詢:SQL原生查詢、HQL通用查詢、C...
  • grep -i 不區分大小寫 --color 添加顏色 alias grep=grep 'grep --color -v 顯示沒有被模式匹配到的行 -o 只顯示被模式匹配到的字元串 回顧: * 任意長度的任意字元 ?任意單個字元 [] 指定範圍內 [^] 指定範圍外正則表達式:Regular EX....
  • 繼上次1.0版本發佈後,根據大家的意見,進行了修改。關於開發技術:在1.0版本完成後,想了很久。多平臺是一個趨勢,如果要進行跨平臺開發,卻又何我之前的初衷背道而馳。(之前的初衷是想學習osx開發,使用swif)後來在公司也在進行此方面的探討(主要是Android和iOS方面)。我作為一個喜歡趕潮流的...
  • 測試環境在linux平臺下,我用的是ubuntu環境。ubuntu安裝可以直接用sudo apt-get install aircrack-nglinux應該可以用yum -y install aircrack-ng 來安裝,如果下載它的安裝包,沒有fangqian的話,非常慢。----------...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...