标签:
一、环境说明
OS:centos6.7 x64
nginx:nginx/1.9.9
ZABBIX:2.4.8
zabbix监控nginx是根据nginx的stub_status模块,抓取status模块所提供的数据。
如果要开启stub_status模块就需要在编译时,添加 --with-http_stub_status_module 参数。
二、修改nginx配置文件
[root@server3 sbin]# cd /usr/local/nginx/conf/ [root@server3 conf]# vim nginx.conf 68 location /nginx-status { 69 stub_status on; 70 access_log off; 71 allow 127.0.0.1; 72 allow 192.168.2.70; 73 allow 192.168.2.12; 74 deny all; 75 }
:wq
[root@server3 conf]# service nginx restart
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
[root@server3 conf]# curl 192.168.2.12/nginx-status
Active connections: 2
server accepts handled requests
14 14 17
Reading: 0 Writing: 1 Waiting: 1
nginx Status 说明:
Active connections: 对后端发起的活动连接数。
server accepts handled requests
14 14 17 nginx 总共处理了14个连接,成功创建了14次握手,总共处理了17请求。
Reading: 0 Writing: 1 Waiting: 1 Reading: nginx 读取客户端的header数, Writing: nginx 返回给客户端的header数, Waiting: nginx 请求处理完成,正在等待下一 请求指令的连接数。
三、在agentd上编写监控nginx的脚本,并且设置属主和属组为zabbix,赋予执行权限
[root@server3 zabbix-2.4.8]# mkdir /usr/local/zabbix-2.4.8/scripts/
脚本和模板地址:链接:http://pan.baidu.com/s/1b0Hm02 密码:631h
将脚本上传至 /usr/local/zabbix-2.4.8/scripts/
[root@server3 scripts]# chown zabbix:zabbix nginx_status.sh
[root@server3 scripts]# chmod +x nginx_status.sh
修改zabbix_agentd.conf配置文件(必须一致性)
[root@server3 scripts]# grep -v ^# /usr/local/zabbix-2.4.8/etc/zabbix_agentd.conf | grep -v ^$ LogFile=/tmp/zabbix_agentd.log
Server=192.168.2.70
ListenPort=10050
ListenIP=192.168.2.12
ServerActive=192.168.2.70:10051
Hostname=192.168.2.12
UnsafeUserParameters=1
UserParameter=nginx.accepts,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh accepts
UserParameter=nginx.handled,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh handled
UserParameter=nginx.requests,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh requests
UserParameter=nginx.connections.active,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh active
UserParameter=nginx.connections.reading,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh reading
UserParameter=nginx.connections.writing,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh writing
UserParameter=nginx.connections.waiting,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh waiting
在zabbix_server 端进行zabbix_get测试,取到数据了,说明没问题。
[root@server bin]# ./zabbix_get -s 192.168.2.12 -p 10050 -k "nginx.requests" 419
[root@server bin]# ./zabbix_get -s 192.168.2.12 -p 10050 -k "nginx.connections.active"
1
导入刚才解压包的模板并添加到该nginx服务器。
等会数据会有了。
zabbix监控nginx完毕。
标签:
原文地址:http://www.cnblogs.com/hukey/p/5460236.html