标签:zabbix 自定义key zabbix实战案例 zabbix监控nginx
自定义key
在zabbix agent端的配置文件由用户通过userparameter指令定义用户自定义参数
userparameter=<key>,<command> userparameter=<key[*]>,<command> $1...$9
实例1(不带参数)
[root@zabbixagent ~]# vim /etc/zabbix/zabbix_agentd.conf
UserParameter=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.conf
UserParameter=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.conf
UserParameter=nginx.status[*],/tmp/status.sh $1
[root@zabbixagent ~]# vim /tmp/status.sh
#!/bin/bash
#
host=10.1.249.168
port=‘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]‘
//参数可以更改本文出自 “似水流年” 博客,请务必保留此出处http://sixijie123.blog.51cto.com/11880770/1880732
标签:zabbix 自定义key zabbix实战案例 zabbix监控nginx
原文地址:http://sixijie123.blog.51cto.com/11880770/1880732