码迷,mamicode.com
首页 > 其他好文 > 详细

Zabbix监控nginx

时间:2016-07-21 20:18:20      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:监控   zabbix   nginx   


编辑nginx.conf文件


//在server内部添加一下内容

location /nginx-status {

    stub_status on;

    access_log  off;    

}


2.zabbix agentd客户端配置


//编辑/usr/local/zabbix/etc/zabbix_agentd.conf

//在文件末尾添加如下

UnsafeUserParameters=1

UserParameter=nginx.accepts,/usr/local/zabbix/scripts/nginx_status.sh accepts  

UserParameter=nginx.handled,/usr/local/zabbix/scripts/nginx_status.sh handled  

UserParameter=nginx.requests,/usr/local/zabbix/scripts/nginx_status.sh requests  

UserParameter=nginx.connections.active,/usr/local/zabbix/scripts/nginx_status.sh active  

UserParameter=nginx.connections.reading,/usr/local/zabbix/scripts/nginx_status.sh reading  

UserParameter=nginx.connections.writing,/usr/local/zabbix/scripts/nginx_status.sh writing  

UserParameter=nginx.connections.waiting,/usr/local/zabbix/scripts/nginx_status.sh waiting

3.编辑nginx_status.sh文件


cat /usr/local/zabbix/scripts/nginx_status.sh

#!/bin/bash

HOST=127.0.0.1(如果在每一个域名下就写域名)

TERM=$1

 

# Functions to return nginx stats

function active {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | grep ‘Active‘ | awk ‘{print $NF}‘

}

function reading {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | grep ‘Reading‘ | awk ‘{print $2}‘

}

function writing {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | grep ‘Writing‘ | awk ‘{print $4}‘

}

function waiting {

        /usr/bin/curl "http://$HOST/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/nginx-status" 2>/dev/null | awk NR==3 | awk ‘{print $2}‘

}

function requests {

        /usr/bin/curl "http://$HOST/nginx-status" 2>/dev/null | awk NR==3 | awk ‘{print $3}‘

}

$TERM


chmod  +x   /usr/local/zabbix/scripts/nginx_status.sh

4.重启zabbix_agentd


service zabbix_agentd restart

5.zabbixweb控制端导入模板

6.zabbix监控的客户端添加nginx模块


本文出自 “系统网站运维” 博客,请务必保留此出处http://cgc243652136qq.blog.51cto.com/3989433/1828323

Zabbix监控nginx

标签:监控   zabbix   nginx   

原文地址:http://cgc243652136qq.blog.51cto.com/3989433/1828323

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!