Keys配置及使用说明
Keys配置
Zabbix自带的key不需要再进行配置,可以直接在web端直接使用建立trigger(触发器)。
自定义keys
自定义keys的配置流程:
①一般新建的keys应该自定义在客户端配置文件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=dis.keepalived.nginx,/van/svr/zabbix-3.0.0/bin/dis_keepalived_nginx.py #(例子)
UserParameter=keepalived.shift.check,/van/svr/zabbix-3.0.0/bin/keepastatus.py #(例子)
举个例子,若要添加一个名字为keepalived.shift.check的key,只需要在配置文件zabbix_agentd.conf按照格式:UserParameter=,添加就可以了:
#(例子)
UserParameter=keepalived.shift.check, /van/svr/zabbix-3.0.0/bin/keepastatus.py
↑ ↑
(key的名字) (key调用脚本的路径,或者直接系统命令)
自定义key通过调用脚本返回的信息zabbix可接受的常用数据类型有:Numeric(整型),Numeric(浮点型),Text(文本)
客户端配置完成后,重启zabbix客户端,自定义的key才会生效。
检查自定义key返回结果
在客户端配置好自定义key后,zabbix_get工具可以在服务器端直接测试key在Server端返回的结果,zabbix_get在/usr/zagt/bin下。
zabbix_get使用命令:
sudo …/bin/zabbix_get -s 192.168.182.87 -k agent.ping
命令解释:
-s 你要查的ip地址,本地的,或者远程的都可以 -p zabbix_agentd的端口 -k key值 1 也就是我们得到的结果,说明87主机的zabbix客户端有起来。
zabbix_agentd.conf的include选项
当keys的数量或者种类不断扩大的时候,配置文件一个个按照”UserParameter=”添加自定义keys会让配置文件zabbix_agentd.conf变得累赘而且自定义keys 难以管理,所以可以使用配置文件中的include选项。
### 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.conf.d/*.conf
Include=/usr/zagt/etc/zabbix_params/*.conf #指定读取此文件夹下所有后缀为.conf的文件
指定的include文件不一定只带有”UserParameter=”参数,可以带有所有配置文件支持的参数。
以下是使用include指定的一个配置文件,主要自定义了keepalived相关的keys:
文件路径及文件名:/usr/zagt/etc/zabbix_params/dis_keepalived.conf
UserParameter=dis.keepalived.nginx,/van/svr/zabbix-3.0.0/bin/dis_keepalived_nginx.py
UserParameter=keepalived.shift.check,/van/svr/zabbix-3.0.0/bin/keepastatus.py