【5】Zabbix添加Macros、Key

系統默認支持的宏:

https://www.zabbix.com/documentation/2.0/manual/appendix/macros/supported_by_location?s[]=macros

定義全局宏:

Administration--General--Macros

wKiom1cjGWHBAfbgAABUDgR7WQw023.png也可以在模版裏面定義宏:

wKiom1cjGbGhBjciAABo5RnLWTE020.png調用剛定義的宏:

wKioL1cjGrTCARp4AAClplhgFCs470.png

wKiom1cjGgKB7kdvAAMnOoMMqRA750.png

wKioL1cjGtPi3DYCAAMrwYy6vtE557.png

Zabbix自定義key

語法:UserParameter=<key>,<shell command>

eg:

1、UserParameter=Memory.free,/usr/local/zabbix/scripts/Memory_status.sh Memory_free

2、UserParameter=Memory.Usage[*],/bin/cat /proc/meminfo |awk '/^$1/{print $$2}'

(初級使用):

wKioL1cjGwmwIDKEAAAaQPbBTpQ626.png

[root@localhost ~]# cd /usr/local/zabbix/etc/
[root@localhost etc]# tail -19 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=
#
# Memory
UserParameter=Memory.total,/usr/local/zabbix/scripts/Memory_status.sh Memory_total
UserParameter=Memory.used,/usr/local/zabbix/scripts/Memory_status.sh Memory_used
UserParameter=Memory.free,/usr/local/zabbix/scripts/Memory_status.sh Memory_free
UserParameter=Swap.total,/usr/local/zabbix/scripts/Memory_status.sh Swap_total
UserParameter=Swap.used,/usr/local/zabbix/scripts/Memory_status.sh Swap_used
UserParameter=Swap.free,/usr/local/zabbix/scripts/Memory_status.sh Swap_free
UserParameter=Total.total,/usr/local/zabbix/scripts/Memory_status.sh Total_total
UserParameter=Total.used,/usr/local/zabbix/scripts/Memory_status.sh Total_used
UserParameter=Total.free,/usr/local/zabbix/scripts/Memory_status.sh Total_free
[root@localhost etc]#

Zabbix Server獲取Agent的值:

[root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Memory.used    //獲取的值單位是kb
123508
[root@CentOS ~]#

wKiom1cjG_jzrKU0AAChDIFNa6c810.png

wKioL1cjHMfArY8eAABC2hgcVwM107.png

wKiom1cjG_qz32VjAACdNBjYZec927.png

wKiom1cjG_qhjVQwAAEkPKcJS4Q720.png

key進階使用:

[root@localhost etc]# pwd
/usr/local/zabbix/etc
[root@localhost etc]# tail -2 zabbix_agentd.conf
# Monitor Memory
UserParameter=Memory.Usage[*],/bin/cat /proc/meminfo |awk '/^$1/{print $$2}'
[root@localhost etc]#
注:[*],*可以代表多個參數。如:command裏面有$1 $2 $3等
get獲取時輸入-k key[$1,$2,$3]
服務器獲取key值:
[root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Memory.Usage[MemTotal]
1004412
[root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Memory.Usage[MemFree]
877996
[root@CentOS ~]# zabbix_get -s 172.24.17.131 -k Memory.Usage[Buffer]
8116
[root@CentOS ~]#

wKioL1cjHVqj1E-LAACL5rzAR9c195.png

wKiom1cjHIyTW3NzAABCyD4DogQ788.png

wKioL1cjHVujCsL7AADQDdo3n-g743.png

wKiom1cjHI3ShL1dAADFt3Fg3JA773.png


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章