1. 程式人生 > >Zabbix實戰-簡易教程--低層次發現(LLD)

Zabbix實戰-簡易教程--低層次發現(LLD)

a-z http ext sector iops 服務 自定義 clas lan

一、概述

自動發現(LLD)提供了一種在為不同實體自動創建監控項,觸發器和圖形的方法。例如,Zabbix可以在你的機器上自動監控磁盤或網卡,而無需為每個磁盤或網卡手動創建監控項。(LLD)

此外,可以配置Zabbix根據定期執行發現後的得到實際結果,來移除不需要的監控項。(根據正則過濾)

二、類型

在Zabbix中,支持六種類型的發現項目:

  • 系統文件的發現;
  • 網絡接口的發現;
  • CPU和CPU內核的發現
  • SNMP OID的發現
  • 使用ODBC SQL查詢的發現
  • Windows服務的發現

三、流程

發現過程的流程如下。

首先,用戶在“配置”→“模板”→“自動發現”列中創建一個發現規則。發現規則包括(1)發現必要實體(例如,磁盤或網卡)的項目和(2)應該根據該項目的值創建的監控項,觸發器和圖形的原型。

其次,用戶也可以自己定義發現類型,只要它們遵循特定的JSON協議。

四、查看自帶LLD

1、我們先查看系統自帶的LLD,選擇 模板管理-->自動發現

技術分享

2、查看到,系統自帶的2個LLD

技術分享

3、隨便點擊一個,比如,我們點擊文件系統的這個

技術分享

4、查看具體監控項

技術分享

需要說的是:{#FSNAME}為宏變量,宏變量,我們之前已經說過,請參考:http://www.cnblogs.com/skyflask/p/7523535.html

五、自定義LLD

流程:(比如采集linux機器上所有磁盤IO)

1、自定義key

UserParameter=custom.vfs.dev.discovery,/bin/sh /etc/zabbix/externalscripts/disk.sh

cat /etc/zabbix/externalscripts/disk.sh

#!/bin/bash
diskarray=(`cat /proc/diskstats |grep -E "\bvd[a-z]\b|\bhd[a-z]\b|\bsd[a-z]\b|\bc0d0p[0-9]\b"|grep -i "\b$1\b"|awk ‘{print $3}‘|sort|uniq   2>/dev/null`)
length2=${#diskarray[@]}
printf "{\n"
printf  ‘\t‘"\"data\":["
for ((i=0;i<$length2;i++))
do
    printf ‘\n\t\t{‘
    printf "\"{#DISK}\":\"${diskarray[$i]}\"}"
    if [ $i -lt $[$length2-1] ];then
            printf ‘,‘
    fi
done
printf  "\n\t]\n"
printf "}\n"

  

2、設置item

# reads completed successfully
UserParameter=custom.vfs.dev.read.ops[*],cat /proc/diskstats | egrep $1 | head -1 | awk {print $$4}
# sectors read
UserParameter=custom.vfs.dev.read.sectors[*],cat /proc/diskstats | egrep $1 | head -1 | awk {print $$6}
# time spent reading (ms)
UserParameter=custom.vfs.dev.read.ms[*],cat /proc/diskstats | egrep $1 | head -1 | awk {print $$7}
# writes completed
UserParameter=custom.vfs.dev.write.ops[*],cat /proc/diskstats | egrep $1 | head -1 | awk {print $$8}
# sectors written
UserParameter=custom.vfs.dev.write.sectors[*],cat /proc/diskstats | egrep $1 | head -1 | awk {print $$10}
# time spent writing (ms)
UserParameter=custom.vfs.dev.write.ms[*],cat /proc/diskstats | egrep $1 | head -1 | awk {print $$11}
# I/Os currently in progress
UserParameter=custom.vfs.dev.io.active[*],cat /proc/diskstats | egrep $1 | head -1 | awk {print $$12}
# time spent doing I/Os (ms)
UserParameter=custom.vfs.dev.io.ms[*],cat /proc/diskstats | egrep $1 | head -1 | awk {print $$13}
#IOPS
UserParameter=custom.vfs.dev.util[*],iostat -x -d -c 1 1|egrep $1|awk {print $NF}

3、設置模板

技術分享

上面忘記說了,我們還可以對發現的磁盤通過正則進行過濾,正則詳情參考:http://www.cnblogs.com/skyflask/p/7520829.html

技術分享

4、綁定主機

最後,選定一臺主機,將模板綁到他上面,就可以看到效果了:

技術分享

技術分享

技術分享

技術分享

技術分享

技術分享

Zabbix實戰-簡易教程--低層次發現(LLD)