zabbix 自定義Key (六)


1、在zabbix_agent端zabbix_agentd.conf配置文件中增加自定義Key(/usr/local/zabbix_agent/etc/zabbix_agentd.conf)

### Option: UserParameter
#       User-defined parameter to monitor. There can be several user-defined parameters.
#       Format: UserParameter=<key>,<shell command>
#       See 'zabbix_agentd' directory for examples.
#
# Mandatory: no接
# Default:
# UserParameter=

UserParameter=Physical_cpu_0_temperature,sensors|grep "id 0"|awk '{print $4}'|awk -F "°" '{print $1}'|awk -F "+" '{print $2}'
 變量  Key 命令

 

就樣一個自定義的Key就完成了,那么我們要怎么來測試這個Key是否生效了呢?配置文件修改完成后需要重啟zabbix_agentd端的服務,然后在zabbix_server端通過zabbix_get查看,是否可以獲取到值,如果獲取到值,表明這個Key就設置成功了。

設置完Key一定記得要通過命令進行驗證啊!!!
# zabbix_get -s 10.16.1.201 -p 10050 -k Physical_cpu_0_temperature
59.0

我們看下,CPU的溫度已經可以正常獲取了,我們的key就設置成功了!

說了第一種定義Key的方法,是在zabbix_agend.conf的主配置文件中修改,大家可以想想,如果需要定義100個Key的話,都寫在主配置文件里,是不是主配置文件會很亂啊,那我們來看看有什么更好的方法呢,接下來看看第二種方法吧!

2、將Key定義在獨立的文件中,然后在主配置文件中進行新引用就好了,下面我們來配置下。

2.1 修改zabbix_agentd.conf 配置(/usr/local/zabbix_agent/etc/zabbix_agentd.conf)

cat /usr/local/zabbix_agent/etc/zabbix_agentd.conf      # 在zabbix_agentd.conf配置文件中通過Include引用自定義Key文件目錄
### Option: Include
#       You may include individual files or all files in a directory in the configuration file.
#       Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time.
#
# Mandatory: no
# Default:
# Include=
# Include=/usr/local/etc/zabbix_agentd.userparams.conf
Include=/usr/local/zabbix_agent/etc/zabbix_agentd.conf.d/

2.2 在/usr/local/zabbix_agent/etc/zabbix_agentd.conf.d目錄寫編寫自定義Key文件

# cat custom_parameters.conf
# Monitor CPU temperature
# cpu_core_0
UserParameter=Physical_cpu_0_temperature,sensors|grep "id 0"|awk '{print $4}'|awk -F "°" '{print $1}'|awk -F "+" '{print $2}'
UserParameter=cpu_0_core0,sensors|grep -A 6 "id 0" | grep "Core 0" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'
UserParameter=cpu_0_core1,sensors|grep -A 6 "id 0" | grep "Core 1" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'
UserParameter=cpu_0_core2,sensors|grep -A 6 "id 0" | grep "Core 2" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'
UserParameter=cpu_0_core3,sensors|grep -A 6 "id 0" | grep "Core 3" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'
UserParameter=cpu_0_core4,sensors|grep -A 6 "id 0" | grep "Core 4" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'
UserParameter=cpu_0_core5,sensors|grep -A 6 "id 0" | grep "Core 5" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'

# cpu_core_1
UserParameter=Physical_cpu_1_temperature,sensors|grep "id 1"|awk '{print $4}'|awk -F "°" '{print $1}'|awk -F "+" '{print $2}'
UserParameter=cpu_1_core0,sensors|grep -A 6 "id 1" | grep "Core 0" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'
UserParameter=cpu_1_core1,sensors|grep -A 6 "id 1" | grep "Core 1" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'
UserParameter=cpu_1_core2,sensors|grep -A 6 "id 1" | grep "Core 2" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'
UserParameter=cpu_1_core3,sensors|grep -A 6 "id 1" | grep "Core 3" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'
UserParameter=cpu_1_core4,sensors|grep -A 6 "id 1" | grep "Core 4" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'
UserParameter=cpu_1_core5,sensors|grep -A 6 "id 1" | grep "Core 5" | awk '{print $3}'|awk -F "°" '{print $1}'|awk  -F "+" '{print $2}'

這讓定義就可以了,如果需要定義的Key較多的話,我們就可以通過這種方式來定義key了,這樣做的好處大家也可以很清楚的看到了,配置清晰、明了,而且不和主配置文件在一起,避免修改key影響主配置文件哈。記得修改完配置文件,記得重啟zabbix_agent服務啊。最好還要通過上面介紹的方法進行驗證下啊。

Key定義好了,我們來看看,如何在zabbix web頁面通過這些來創建監控項吧!

3、zabbix web頁面,通過創建的自定義Key來建立監控項

zabbix_monitory_31

zabbix_monitory_22

zabbix_monitory_23

zabbix_monitory_29

這里我們以一個自定義key來介紹了,多個key的創建方法一樣哦,小伙伴們自己動手試下吧。

zabbix_monitory_30

      這是通過自定義監控一顆物理CPU溫度匯總的圖形,大家可以看到,自定義Key是不是很好用啊。只要我們在服務器上可以獲取的值,都可以通過自定義Key的方法來進行監控,也非常的靈活!下面在來設置上監控溫度的觸發器吧。

zabbix_monitory_26

zabbix_monitory_27

創建

到這里,自定義Key我們就介紹完了,可以在回顧下,我們都做了什么?

1、在zabbix_agent端配置文件增加自定義Key

2、重啟zabbix_agentd服務

3、在zabbix_server端通過zabbix_get驗證自定義key是否生效

4、在zabbix_web頁面通過自定義key創建監控項

5、在zabbix_web頁面給自定義key監控項創建圖形

6、自定義Key監控項創建觸發器


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM