天天看点

【5】Zabbix添加Macros、Key

系统默认支持的宏:

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

定义全局宏:

Administration--General--Macros

【5】Zabbix添加Macros、Key
也可以在模版里面定义宏:
【5】Zabbix添加Macros、Key
调用刚定义的宏:
【5】Zabbix添加Macros、Key
【5】Zabbix添加Macros、Key
【5】Zabbix添加Macros、Key

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}'

(初级使用):

【5】Zabbix添加Macros、Key

[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 ~]#      
【5】Zabbix添加Macros、Key
【5】Zabbix添加Macros、Key
【5】Zabbix添加Macros、Key
【5】Zabbix添加Macros、Key

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 ~]#      
【5】Zabbix添加Macros、Key
【5】Zabbix添加Macros、Key