系统默认支持的宏:

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