一、环境说明
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配置文件
[[email protected] sbin]# cd /usr/local/nginx/conf/ [[email protected] 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 [[email protected] conf]# service nginx restartnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successfulStopping nginx: [ OK ]Starting nginx: [ OK ] [[email protected] conf]# curl 192.168.2.12/nginx-statusActive 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,赋予执行权限
[[email protected] 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/
[[email protected] scripts]# chown zabbix:zabbix nginx_status.sh [[email protected] scripts]# chmod +x nginx_status.sh
修改zabbix_agentd.conf配置文件(必须一致性)
[[email protected] scripts]# grep -v ^# /usr/local/zabbix-2.4.8/etc/zabbix_agentd.conf | grep -v ^$ LogFile=/tmp/zabbix_agentd.logServer=192.168.2.70ListenPort=10050ListenIP=192.168.2.12ServerActive=192.168.2.70:10051Hostname=192.168.2.12UnsafeUserParameters=1UserParameter=nginx.accepts,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh acceptsUserParameter=nginx.handled,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh handledUserParameter=nginx.requests,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh requestsUserParameter=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 readingUserParameter=nginx.connections.writing,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh writingUserParameter=nginx.connections.waiting,/usr/local/zabbix-2.4.8/scripts/nginx_status.sh waiting
在zabbix_server 端进行zabbix_get测试,取到数据了,说明没问题。
[[email protected] bin]# ./zabbix_get -s 192.168.2.12 -p 10050 -k "nginx.requests" 419[[email protected] bin]# ./zabbix_get -s 192.168.2.12 -p 10050 -k "nginx.connections.active"1
导入刚才解压包的模板并添加到该nginx服务器。等会数据会有了。 zabbix监控nginx完毕。
时间: 2024-10-25 06:35:48