Zabbix Nginx的监控

参考资料:http://www.ttlsa.com/zabbix/zabbix-monitor-nginx-performance/

打开 Nginxstatus 页面,并重启

[root@zabbix vhosts]# cat nginx_status.conf 
server {
    listen 90;
    server_name _;
    location /ngx_status {
        stub_status on;
        access_log off;
        allow 127.0.0.1;
        deny all;
    }
}
[root@zabbix vhosts]# nginx -s reload

本地访问测试

[root@zabbix vhosts]# curl http://127.0.0.1:90/ngx_status
Active connections: 2       # 活跃的连接数量
server accepts handled requests
 12178 12178 18413          # 总共处理了12178个连接 , 成功创建12178次握手, 总共处理了18413个请求
Reading: 0 Writing: 1 Waiting: 1        # 读取客户端的连接数: 0  响应数据到客户端的数量: 1  Nginx 已经处理完正在等候下一次请求指令的驻留连接(开启 keep-alive 的情况下,这个值等于 active – (reading+writing))

创建监控脚本

HOST="127.0.0.1"
PORT="80"
 
# 检测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

添加 zabbix agent 的自定义conf,重启zabbix agent

[root@zabbix zabbix_agentd.conf.d]# cat ngx-status.conf 
UserParameter=nginx.status[*],/scripts_test/ngx-status.sh $1

添加Nginx 模版

你可能感兴趣的:(Zabbix Nginx的监控)