1. 程式人生 > >linux檔案/proc/diskstats註解

linux檔案/proc/diskstats註解

如果不用命令檢視某些系統狀態,比如需要自己編寫python等指令碼的時候,就要用到各種的系統檔案,這裡註解磁碟資訊檔案/proc/diskstats。

[[email protected] proc]# cat diskstats 
  11       0 sr0 18 0 2056 383 0 0 0 0 0 376 383
   8       0 sda 8821 34 484957 208310 1062 175 37797 252131 0 89700 460277
   8       1 sda1 2194 0 50096 41631 10 0 4137 31 0 38002 41642
   8       2 sda2 6596 34 432757 166586 1052 175 33660 252100 0 55376 418542
   8      16 sdb 325 0 6662 2621 33 4 672 8216 0 3507 10837
   8      32 sdc 170 0 3184 3720 0 0 0 0 0 3630 3720
 253       0 dm-0 6587 0 431099 166500 1264 0 34332 326232 0 55676 492732
 253       1 dm-1 99 0 4496 375 0 0 0 0 0 369 375
 253       2 dm-2 48 0 2112 2168 0 0 0 0 0 2093 2168

/proc/diskstats檔案比/sys/block/sda/stat檔案多3個域,從左至右分別對應主裝置號,次裝置號和裝置名稱。後續的11個域在這兩個檔案裡是相同的,它們的函義將在下面解釋。除了第9個域,所有的域都是從啟動時的累積值。

第4個域:讀完成次數 ----- 讀磁碟的次數,成功完成讀的總次數。

(number of issued reads. This is the total number of reads completed successfully.)

第5個域:合併讀完成次數, 第6個域:合併寫完成次數。為了效率可能會合並相鄰的讀和寫。從而兩次4K的讀在它最終被處理到磁碟上之前可能會變成一次8K的讀,才被計數(和排隊),因此只有一次I/O操作。這個域使你知道這樣的操作有多頻繁。

(number of reads merged)

第6個域:讀扇區的次數,成功讀過的扇區總次數。

(number of sectors read. This is the total number of sectors read successfully.)

第7個域:讀花費的毫秒數,這是所有讀操作所花費的毫秒數(用__make_request()到end_that_request_last()測量)。
(number of milliseconds spent reading. This is the total number of milliseconds spent by all reads (as measured from __make_request() to end_that_request_last()).)

第8個域:寫完成次數 ----寫完成的次數,成功寫完成的總次數。

(number of writes completed. This is the total number of writes completed successfully.)

第9個域:合併寫完成次數 -----合併寫次數。

(number of writes merged Reads and writes which are adjacent to each other may be merged for efficiency. Thus two 4K reads may become one 8K read before it is ultimately handed to the disk, and so it will be counted (and queued) as only one I/O. This field lets you know how often this was done.)

第10個域:寫扇區次數 ---- 寫扇區的次數,成功寫扇區總次數。

(number of sectors written. This is the total number of sectors written successfully.)

第11個域:寫操作花費的毫秒數 — 寫花費的毫秒數,這是所有寫操作所花費的毫秒數(用__make_request()到end_that_request_last()測量)。

(number of milliseconds spent writing This is the total number of milliseconds spent by all writes (as measured from __make_request() to end_that_request_last()).)

第12個域:正在處理的輸入/輸出請求數 – -I/O的當前進度,只有這個域應該是0。當請求被交給適當的request_queue_t時增加和請求完成時減小。

(number of I/Os currently in progress. The only field that should go to zero. Incremented as requests are given to appropriate request_queue_t and decremented as they finish.)

第13個域:輸入/輸出操作花費的毫秒數 ----花在I/O操作上的毫秒數,這個域會增長只要field 9不為0。

(number of milliseconds spent doing I/Os. This field is increased so long as field 9 is nonzero.)

第14個域:輸入/輸出操作花費的加權毫秒數 ----- 加權, 花在I/O操作上的毫秒數,在每次I/O開始,I/O結束,I/O合併時這個域都會增加。這可以給I/O完成時間和儲存那些可以累積的提供一個便利的測量標準。
  
總結來說,14個域對應以下含義
裝置號 編號 裝置 讀完成次數 合併完成次數 讀扇區次數 讀操作花費毫秒數 寫完成次數 合併寫完成次數 寫扇區次數 寫操作花費的毫秒數 正在處理的輸入/輸出請求數 輸入/輸出操作花費的毫秒數 輸入/輸出操作花費的加權毫秒數。
除正在處理的輸入/輸出請求數這項是非累積值外,其他磁碟統計都是累積值。

zabbix中磁碟使用情況就是從diskstats採集,磁碟使用率計算方式為:

兩次採集的輸入/輸出操作花費的毫秒數之差 / 採集間隔時間

例如:第一次採集輸入/輸出操作花費的毫秒數為90258834,間隔10秒後採集的值為90258710

那麼磁碟使用率為 (90258710ms - 90258834ms)/ 10*1000ms = 0.0124,也就是1.24%