zabbix監控linux服務器的磁盤I/O

基本原理:經過分析/proc/diskstats文件,來對IO的性能進行監控。解釋以下:

html

+++++++++++++++++++++++++++對/proc/diskstats的解釋++++++++++++++++++++++++++++++++++++++++++++git

[root@localhost bin]# cat /proc/diskstats | grep sda | head -1github

8 0 sda 73840 10263 3178156 91219 1110085 4192562 42423152 1275861 0 447798 1366379app

第一至第三個域,分別是主設備號,次設備號,設備名稱

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

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


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

(number of reads merged)ui


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

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


第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完成時間和存儲那些能夠累積的提供一個便利的測量標準。

(number of milliseconds spent doing I/Os. This field is incremented at each I/O start, I/O completion, I/O merge, or read of these stats by the number of I/Os in progress (field 9) times the number of milliseconds spent doing I/O since the last update of this field. This can provide an easy measure of both I/O completion time and the backlog that may be accumulating.)

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


接下來就是在zabbix agent的配置文件作操做:
vi /usr/local/zabbix/etc/zabbix_agentd.conf

UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$4}'                    //磁盤讀的次數

UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$7}'                     //磁盤讀的毫秒數

UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$8}'                   //磁盤寫的次數

UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$11}'                  //磁盤寫的毫秒數

UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$12}'            

UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$13}'                       //花費在IO操做上的毫秒數

UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$6}'             //讀扇區的次數(一個扇區的等於512B)

UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | grep $1 | head -1 | awk '{print $$10}'          //寫扇區的次數(一個扇區的等於512B)


測試命令以下:

[root@localhost bin]# ./zabbix_get -s 10.2.11.11 -p 10050 -k custom.vfs.dev.write.ops[sda]

111153

添加指標:思路:首先添加模板 ,而後在模板上添加item。
指標細節:

第一個指標Name:      Disk:$1:Read:Bytes/sec

                  Key:          custom.vfs.dev.read.sectors[sda]

                  Units:        B/sec

                  Store value: speed per second    //會進行差值計算

                  Use custom multiplier     512      //會對值乘以512,由於這裏是一個扇區,轉換爲字節爲512B

                  




同理,其餘指標方式,添加以下:

第二個指標:Name:      Disk:$1:Write:Bytes/sec

                  Key:          custom.vfs.dev.write.sectors[sda]

                  Units:        B/sec

                  Store value: speed per second

                  Use custom multiplier     512

第三個指標:Name:      Disk:$1:Read:ops per second

                  Key:          custom.vfs.dev.read.ops[sda]

                  Units:        ops/second

                  Store value: speed per second

第四個指標:Name:      Disk:$1:Write:ops per second

                  Key:          custom.vfs.dev.write.ops[sda]

                  Units:        ops/second

                  Store value: speed per second

第五個指標:Name:     Disk:$1:Read:ms

                  Key:         custom.vfs.dev.read.ms[sda]

                  Units:      ms

                  Store value: speed per second

第六個指標:Name:     Disk:$1:Write:ms

                  Key:         custom.vfs.dev.write.ms[sda]

                  Units:      ms

                  Store value: speed per second



轉自:http://blog.chinaunix.net/uid-26446098-id-4964263.html

github:https://github.com/grundic/zabbix-disk-performance

經過ansible推送磁盤監控的配置:https://github.com/meissnerIT/mit.zabbix-agent.disk-performance

相關文章
相關標籤/搜索