Zabbix监控nginx性能

Zabbix wangleiadmin 1105℃ 0评论
启动nginx status
server {
  
    location /ngx_status 
    {
        stub_status on;
        access_log off;
        allow 127.0.0.1;     #允许IP
        deny all;
    }
}

/etc/init.d/nginx restart            #重启nginx
curl http://127.0.0.1/ngx_status   #打开status页面验证
Active connections: 1
server accepts handled requests
 185 185 441
Reading: 0 Writing: 1 Waiting: 0
active connections – 活跃的连接数量
server accepts handled requests — 总共处理了185个连接 , 成功创建185次握手, 总共处理了441个请求
reading — 读取客户端的连接数.
writing — 响应数据到客户端的数量
waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading+writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接.
cd /usr/local/bin/

cat ngx_status.sh
#!/bin/bash
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
chmod +x ngx-status.sh
Zabbix客户端配置文件添加
UserParameter=nginx.status[*],/usr/local/bin/ngx_status.sh $1
zabbix_get -s 192.168.10.100 -p 10050 -k nginx.status[ping]           #zabbix服务端验证是否出数据
1

模版链接:http://pan.baidu.com/s/1mhL6FGk 密码:ytzv

出图
__~122O]4_T[C}}FA)96O74

转载请注明:暖风 » Zabbix监控nginx性能

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址