一.检查配置状态页

1,检查nginx是否安装ngx_http_stub_status_module模块

如果没有安装,需要重新编译。

# nginx  -V | grep http_stub   

ngx_http_stub_status_module (static)

# nginx   -v

Tengine version: Tengine/2.1.1 (nginx/1.6.2)

2,首先在nginx的server段配置对应的信息,然后访问监控zabbix页面

server {

    listen  8000;

    server_name  _;

    location /ngx_status

    {

        stub_status on;

        access_log off;

#allow all;   可以设置需要那些主机访问

#deny all;

    }

}

3,重新加载nginx,访问测试

# service nginx reload

# curl 172.16.100.201:8000/ngx_status

Active connections: 135  

server accepts handled requests request_time

 13711907 25715823 5175039843

Reading: 0 Writing: 12 Waiting: 123

说明:

Active connections: 135

#//正在活跃的连接数

server accepts handled requests

#处理了13711907次连接,创建25715823次握手,共5175039843请求。

13711907 25715823 5175039843

Reading: 0 Writing: 1 Waiting: 1 

# Reading:读取客户端header数,Writing:返回客户端header数,Waiting:请求完成,等待下一次连接。

1,创建脚本

#cd /etc/zabbix

# vim nginx-check.sh

#!/bin/bash

# DateTime: 2015-10-25

# AUTHOR:凉白开

# WEBSITE: http://www.ttlsa.com

# Description:zabbix监控nginx性能以及进程状态

# Note:此脚本需要配置在被监控端,否则ping检测将会得到不符合预期的结果

HOST=”127.0.0.1″

PORT=”8000″

# 检测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

2,赋予权限

# chmod o+x nginx-check.sh 

3,在 Include=/etc/zabbix/zabbix_agentd.d/目录下创建配置文件,并加入以下内容

# cd /etc/zabbix/zabbix_agentd.d/

# vim nginx-params.conf

UserParameter=nginx[*],/etc/zabbix/nginx-check.sh $1

3,重启zgent

# /etc/init.d/zabbix-agent restart

4,web端配置导入下面模板(模版下载:Nginx-template.xml

5,在主机管理里面给主机链接到对应模板

6,添加之后就可以看到nginx的情况了

发表评论

后才能评论