首页 > 其他 > 详细

zabbix监控nginx状态(三)

时间:2017-01-12 03:22:07      阅读:279      评论:0      收藏:0      [点我收藏+]

1.nginx配置增加状态

vim nginx_status.conf
server {
    listen  *:81 default_server;
    server_name _;
    location /nginx_status {
        stub_status on;
        access_log off;
    }
    location /upstream_status {
        check_status;
        access_log off;
    }
    
    location /req_status_server {
        req_status_show server;
        access_log off;
    }
    #location /req_status_url {
    #    req_status_show url;
    #    access_log off;
    #}
}

2.测试访问

# curl http://localhost:81/nginx_status
Active connections: 573 
server accepts handled requests request_time
 146168002 146168002 195194137 12912677608
Reading: 0 Writing: 13 Waiting: 560


3.创建监控脚本

vim nginx_stat.sh 
#!/bin/bash

HOST="127.0.0.1"
PORT="81"
  
function ping {
    /sbin/pidof nginx | wc -l 
}

function active {
    /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| grep ‘Active‘ | awk ‘{print $NF}‘
}
function reading {
    /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| grep ‘Reading‘ | awk ‘{print $2}‘
}
function writing {
    /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| grep ‘Writing‘ | awk ‘{print $4}‘
}
function waiting {
    /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| grep ‘Waiting‘ | awk ‘{print $6}‘
}
function accepts {
    /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $1}‘
}
function handled {
    /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $2}‘
}
function requests {
    /usr/bin/curl "http://${HOST}:${PORT}/nginx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $3}‘
}
$1

4.增加配置文件参数

vim /usr/local/zabbix-agent/etc/zabbix_agentd.conf
UserParameter=nginx.status[*],/bin/bash /usr/local/zabbix-agent/scripts/nginx_stat.sh $1

5.重启进程

 /etc/init.d/zabbix_agentd restart

6.增加模板

技术分享

7.增加item

技术分享

技术分享

8.增加监控图像

技术分享

9.查看监控

技术分享

本文出自 “深呼吸再出击” 博客,请务必保留此出处http://ckl893.blog.51cto.com/8827818/1891137

zabbix监控nginx状态(三)

原文:http://ckl893.blog.51cto.com/8827818/1891137

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!