1、在zabbix_agent端zabbix_agentd.conf配置文件中增加自定义Key(/usr/local/zabbix_agent/etc/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=Physical_cpu_0_temperature,sensors|grep "id 0"|awk '{print $4}'|awk -F "°" '{print $1}'|awk -F "+" '{print $2}'
变量 Key 命令 就样一个自定义的Key就完成了,那么我们要怎么来测试这个Key是否生效了呢?配置文件修改完成后需要重启zabbix_agentd端的服务,然后在zabbix_server端通过zabbix_get查看,是否可以获取到值,如果获取到值,表明这个Key就设置成功了。 设置完Key一定记得要通过命令进行验证啊!!!# zabbix_get -s 10.16.1.201 -p 10050 -k Physical_cpu_0_temperature
59.0
我们看下,CPU的温度已经可以正常获取了,我们的key就设置成功了!
说了第一种定义Key的方法,是在zabbix_agend.conf的主配置文件中修改,大家可以想想,如果需要定义100个Key的话,都写在主配置文件里,是不是主配置文件会很乱啊,那我们来看看有什么更好的方法呢,接下来看看第二种方法吧! 2、将Key定义在独立的文件中,然后在主配置文件中进行新引用就好了,下面我们来配置下。
2.1 修改zabbix_agentd.conf 配置(/usr/local/zabbix_agent/etc/zabbix_agentd.conf)
cat /usr/local/zabbix_agent/etc/zabbix_agentd.conf # 在zabbix_agentd.conf配置文件中通过Include引用自定义Key文件目录### 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.
Include=/usr/local/zabbix_agent/etc/zabbix_agentd.conf.d/
2.2 在/usr/local/zabbix_agent/etc/zabbix_agentd.conf.d目录写编写自定义Key文件
# cat custom_parameters.conf
# Monitor CPU temperature