1.定义监控项
已经把监控项做成模板了,可以直接下载
http://file.yangyijing.cn/zabbix/nginx/check_ngx.sh
2.加载zabbix-agent的配置文件
cat /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf
UserParameter=nginx.status[*],/server/scripts/check_ngx.sh $1
systemctl restart zabbix-agent2
3.加载脚本
cat /server/scripts/check_ngx.sh
#!/bin/bash
HOST="localhost"
PORT="80"
# 检测nginx进程是否存在
function ping {
/sbin/pidof nginx | wc -l
}
# 检测nginx性能
function active {
/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
# 执行function
$1
标签:function,bin,http,status,nginx,zabbix,awk,监控,PORT
From: https://www.cnblogs.com/yangtao416/p/16610014.html