环境说明:
OS :CentOS 5.4 64位
nginx (0.8.46):192.168.100.135
zabbix server(2.0.6) :192.168.100.105
首先 zabbix 监控nginx 是根据nginx的Stub Status 模块,抓取Status模块所提供的数据。
如果想启用Stub Status 模块,在编译nginx 的时候要加上参数 --with-http_stub_status_module 例如:
./configure --user=www --group=www --prefix=/opt/app/nginx --with-http_stub_status_module --with-http_ssl_module
在nginx.conf 里添加 Status 配置,端口801(自己随意),
点击(此处)折叠或打开
-
server {
-
listen 801;
-
server_name 192.168.100.135;
-
-
location /webstatus {
-
stub_status on;
-
access_log off;
-
allow 127.0.0.1;
-
allow 192.168.100.105;
-
allow 192.168.100.135;
-
deny all;
-
}
- }
访问Status 如下图:
![](http://blog.chinaunix.net/attachment/201307/16/24250828_1373945842P6tJ.jpg)
nginx Status 说明:
Active connections: 对后端发起的活动连接数。
server accepts handled requests
64603417 64603417 90009784 nginx 总共处理了64603417个连接,成功创建了64603417次握手,总共处理了90009784请求。
Reading: 11 Writing: 2 Waiting: 488 Reading: nginx 读取客户端的header数, Writing: nginx 返回给客户端的header数, Waiting: nginx 请求处理完成,正在等待下一 请求指令的连接。
在zabbix 加入配置
点击(此处)折叠或打开
-
[man@web-nginx02 ~]$ vim /etc/zabbix/zabbix_agentd.conf
-
-
加入
-
-
#nginx
-
UserParameter=nginx.accepts,/usr/local/sbin/nginx_status.sh accepts
-
UserParameter=nginx.handled,/usr/local/sbin/nginx_status.sh handled
-
UserParameter=nginx.requests,/usr/local/sbin/nginx_status.sh requests
-
UserParameter=nginx.connections.active,/usr/local/sbin/nginx_status.sh active
-
UserParameter=nginx.connections.reading,/usr/local/sbin/nginx_status.sh reading
-
UserParameter=nginx.connections.writing,/usr/local/sbin/nginx_status.sh writing
- UserParameter=nginx.connections.waiting,/usr/local/sbin/nginx_status.sh waiting
新建脚本,注意修改自己的HOST,PORT 变量
点击(此处)折叠或打开
-
[man@web-nginx02 ~]$ cat /usr/local/sbin/nginx_status.sh
-
-
#!/bin/bash
-
# Script to fetch nginx statuses for tribily monitoring systems
-
# Author: krish@toonheart.com
-
# License: GPLv2
-
-
# Set Variables
-
BKUP_DATE=`/bin/date +%Y%m%d`
-
LOG="/etc/zabbix/webstatus.log"
-
HOST=`/sbin/ifconfig eth1 | sed -n '/inet /{s/.*addr://;s/ .*//;p}'`
-
PORT="801"
-
-
# Functions to return nginx stats
-
-
function active {
-
/usr/bin/curl "" 2>/dev/null| grep 'Active' | awk '{print $NF}'
-
}
-
-
function reading {
-
/usr/bin/curl "" 2>/dev/null| grep 'Reading' | awk '{print $2}'
-
}
-
-
function writing {
-
/usr/bin/curl "" 2>/dev/null| grep 'Writing' | awk '{print $4}'
-
}
-
-
function waiting {
-
/usr/bin/curl "" 2>/dev/null| grep 'Waiting' | awk '{print $6}'
-
}
-
-
function accepts {
-
/usr/bin/curl "" 2>/dev/null| awk NR==3 | awk '{print $1}'
-
}
-
-
function handled {
-
/usr/bin/curl "" 2>/dev/null| awk NR==3 | awk '{print $2}'
-
}
-
-
function requests {
-
/usr/bin/curl "" 2>/dev/null| awk NR==3 | awk '{print $3}'
-
}
-
-
# Run the requested function
- $1
二,在zabbix 导入模板,并把主机加入模板中。
![](/image/default/fj.png)
![](http://blog.chinaunix.net/attachment/201307/16/24250828_1373946069v88z.jpg)
重启agent
在zabbix server 端进行zabbix_get测试,取到数据了,说明没问题。
点击(此处)折叠或打开
-
[pomelo@jumper ~]$ zabbix_get -s 192.168.100.135 -p 10050 -k "nginx.connections.active"
- 559
三,查看图型
![](http://blog.chinaunix.net/attachment/201307/16/24250828_1373946084D9dR.jpg)