Nginx配置
首先需要开启stub_status模块功能,用于查看Nginx状态信息,通过nginx -V 可以查看是否安装这个模块。有的话我们在nginx配置的server段中如入 location /ngx_status 路径。
列子:
代码语言:javascript复制 server {
listen 18118;
server_name 127.0.0.1;
location /ngx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
}
重启加载nginx后
代码语言:javascript复制 curl http://127.0.0.1/ngx_status
#测试获取数据吧
zabbix自定义脚本
/usr/local/zabbix-agent/scripts/nginx_check.sh
代码语言:javascript复制#!/bin/bash
HOST="127.0.0.1"
PORT="18118"
# 检测nginx进程是否存在
function ping {
/sbin/pidof nginx | wc -l
}
# 检测nginx性能
function active {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
/usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk '{print $3}'
}
# 执行function
$1
/usr/local/zabbix-agent/etc/zabbix_agentd.conf.d/nginx.key
代码语言:javascript复制#nginx
UserParameter=nginx.status[*],/usr/local/zabbix-agent/scripts/nginx_check.sh $1
模板
Template App NGINX
测试 debug
代码语言:javascript复制tail /tmp/zabbix_agentd.log
# 查看日志
/usr/local/zabbix3.0/bin/zabbix_get -s 121.xx.xx.xx -k nginx.status[accepts]
#服务端抓取数据测试