自定义key
在zabbix agent端的配置文件由用户通过userparameter指令定义用户自定义参数
userparameter=, userparameter= , $1...$9
实例1(不带参数)
[root@zabbixagent ~]# vim /etc/zabbix/zabbix_agentd.confUserParameter=system.memory.free,awk '/^MemFree/{print $2}' /proc/meminfo[root@zabbixagent ~]# systemctl restart zabbix-agent在服务器端测试[root@zabbixserver ~]# zabbix_get -s 10.1.249.168 -k 'system.memory.free'89844
示例2(带参数)
[root@zabbixagent ~]# vim /etc/zabbix/zabbix_agentd.confUserParameter=system.memory.usage[*],awk '/^$1/{print $$2}' /proc/meminfo[root@zabbixagent ~]# systemctl restart zabbix-agent在服务器端测试[root@zabbixserver ~]# zabbix_get -s 10.1.249.168 -k 'system.memory.usage[MemTotal]'493224[root@zabbixserver ~]# zabbix_get -s 10.1.249.168 -k 'system.memory.usage[MemFree]'89188[root@zabbixserver ~]# zabbix_get -s 10.1.249.168 -k 'system.memory.usage[MemAvailable]'342664
实战案例
(监控nginx status状态页面的各项指标)
[root@zabbixagent ~]# vim /etc/zabbix/zabbix_agentd.confUserParameter=nginx.status[*],/tmp/status.sh $1[root@zabbixagent ~]# vim /tmp/status.sh #!/bin/bash#host=10.1.249.168port='80'statusurl='/status'active() { curl -s http://${host}:${port}${statusurl} | awk '/^Active/{print $3}'}accepts() { curl -s http://${host}:${port}${statusurl} | awk 'NR==3{print $1}'}handled() { curl -s http://${host}:${port}${statusurl} | awk 'NR==3{print $2}'}requests() { curl -s http://${host}:${port}${statusurl} | awk 'NR==3{print $3}'}reading() { curl -s http://${host}:${port}${statusurl} | awk 'NR==4{print $2}'}writing() { curl -s http://${host}:${port}${statusurl} | awk 'NR==4{print $4}'}waiting() { curl -s http://${host}:${port}${statusurl} | awk 'NR==4{print $6}'}$1[root@zabbixagent ~]# chmod +x /tmp/status.sh在服务器端测试[root@zabbixserver ~]# zabbix_get -s 10.1.249.168 -k 'nginx.status[accepts]'//参数可以更改