在被监控端操作:
1、编写脚本获取上面的 key 值
mkdir /data/sh/
vim /data/sh/nginx_status.sh
chmod a+x nginx_status.sh #增加脚本执行权限
#!/bin/bash case $2 in active) curl -s $1 2>/dev/null| grep 'Active' | awk '{print $3}' ;; accepts) curl -s $1 2>/dev/null| grep 'Reading' | awk '{print $2}' ;; handled) curl -s $1 2>/dev/null| grep 'Writing' | awk '{print $4}' ;; requests) curl -s $1 2>/dev/null| grep 'Waiting' | awk '{print $6}' ;; reading) curl -s $1 2>/dev/null| awk NR==3 | awk '{print $1}' ;; writing) curl -s $1 2>/dev/null| awk NR==3 | awk '{print $2}' ;; waiting) curl -s $1 2>/dev/null| awk NR==3 | awk '{print $3}' ;; *) echo "Usage: url:$1 $2 { active | accepts | handled | requests | reading | writing | waiting }" ;; esac ~
2、添加自定义 key 配置文件
vim /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf
UserParameter=nginx.status[*],/data/sh/nginx_status.sh $1 $2
systemctl restart zabbix-agent #重启zabbix被监控端
3. Zabbix 服务端测试能否拿到 Key
zabbix_get -s 192.168.100.31 -k nginx.status['127.0.0.1/nginx-status','active']
4. Zabbix 中增加Nginx 监控模板