系统默认支持的宏:
https://www.zabbix.com/documentation/2.0/manual/appendix/macros/supported_by_location?s[]=macros
定义全局宏:
Administration--General--Macros
也可以在模版里面定义宏:
调用刚定义的宏:
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}‘
(初级使用):
[[email protected] ~]# cd /usr/local/zabbix/etc/ [[email protected] 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 [[email protected] etc]#
Zabbix Server获取Agent的值:
[[email protected] ~]# zabbix_get -s 172.24.17.131 -k Memory.used //获取的值单位是kb 123508 [[email protected] ~]#
key进阶使用:
[[email protected] etc]# pwd /usr/local/zabbix/etc [[email protected]host etc]# tail -2 zabbix_agentd.conf # Monitor Memory UserParameter=Memory.Usage[*],/bin/cat /proc/meminfo |awk ‘/^$1/{print $$2}‘ [[email protected] etc]# 注:[*],*可以代表多个参数。如:command里面有$1 $2 $3等 get获取时输入-k key[$1,$2,$3] 服务器获取key值: [[email protected] ~]# zabbix_get -s 172.24.17.131 -k Memory.Usage[MemTotal] 1004412 [[email protected] ~]# zabbix_get -s 172.24.17.131 -k Memory.Usage[MemFree] 877996 [[email protected] ~]# zabbix_get -s 172.24.17.131 -k Memory.Usage[Buffer] 8116 [[email protected] ~]#
时间: 2024-10-05 16:09:12