访次: AmazingCounters.com 次

使用zabbix监控nginx

在zabbix agentd客户端上,查看nginx是否加载了--with-http_stub_status_module。因为zabbix监控nginx是根据 nginx的Stub Status模块,抓取Status模块所提供的数据。假如以前没开启,现在想启用StubStatus 模块,在编译nginx 的时候要加上参数 --with-http_stub_status_module,执行./configure && make就可以了,不用make install。不过,一般情况下都是安装了的。

1.在nginx的配置文件中,添加status配置。

1 location/nginx-status {
2   stub_status on;
3   access_log  off;
4   allow 127.0.0.1;
5   allow 192.168.1.10;  #(zabbix服务器的IP地址,一般是内网地址)
6   deny all;       
7 }

2.访问设置好的nginx-status链接,如图所示:

3.nginx Status 详细说明:

Active connections:对后端发起的活动连接数;

server accepts 2349542:nginx 总共处理了2349542个连接;

handled:成功创建了64603417次握手;

requests:总共处理了8798670请求。

Reading:nginx读取客户端的header数;

Writing: nginx 返回给客户端的header数;

Waiting: nginx 请求处理完成,正在等待下一请求指令的连接。

4.在agentd上编写监控nginx的脚本,并且设置属主和属组为zabbix,赋予执行权限。

 1 cd /usr/local/zabbix/scripts
 2 cat nginx_status.sh        
 3 #!/bin/bash
 4 # Script to fetch nginx statuses for tribily monitoring systems
 5 # Author: krish@toonheart.com
 6 # License: GPLv2
 7 # Set Variables
 8 BKUP_DATE=`/bin/date +%Y%m%d`
 9 LOG="/data/log/zabbix/webstatus.log"
10 HOST=127.0.0.1
11 PORT="80"
12 # Functions to return nginx stats
13 function active {
14   /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Active' | awk '{print $NF}'
15   }
16 function reading {
17   /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Reading' | awk '{print $2}'
18   }
19 function writing {
20   /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Writing' | awk '{print $4}'
21   }
22 function waiting {
23   /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
24   }
25 function accepts {
26   /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $1}'
27   }
28 function handled {
29   /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $2}'
30   }
31 function requests {
32   /usr/bin/curl "http://$HOST:$PORT/nginx-status" 2>/dev/null| awk NR==3 | awk '{print $3}'
33   }
34 # Run the requested function
35 $1
36 chmod o+x nginx_status.sh
37 chown zabbix.zabbix nginx_status.sh
38 ll
39 total 4
40 -rwxr-xr-x 1 zabbix zabbix 1273 May 13 17:42 nginx_status.sh

 

posted @ 2016-03-31 17:09  IT老登  阅读(223)  评论(0编辑  收藏  举报
访次: AmazingCounters.com 次