Nginx要被Zabbix监控需要stub_status这个模块,由于源码编译安装时候没有装,所以需要先装载这个模块。
1.查看nginx的安装配置
cd /usr/local/nginx/sbin/
./nginx -V
nginx version: nginx/1.4.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=/home/package/pcre-8.35 --with-zlib=/home/package/zlib-1.2.8 --with-openssl=/home/package/openssl-1.0.1g
进入nginx的解压文件夹
./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-pcre=/home/package/pcre-8.35 --with-zlib=/home/package/zlib-1.2.8 --with-openssl=/home/package/openssl-1.0.1g
**--with-http_stub_status_module(在原有配置加上这句)**
......
make
然后 不要make install
直接把objs里的nginx文件拷贝替换原来sbin下的nginx(当然最好备份原来的,这样出了问题还可以还原)
2.
首先,在nginx 下touch一个status
并通过网页访问检测,内容为:
Active connections: 1
server accepts handled requests
20 5 9
Reading: 0 Writing; 1 Waiting: 0
[root@server2]# cd /etc/zabbix/zabbix_agentd.d/
[root@server2 zabbix_agentd.d]# vim nginx.conf
UserParameter=nginx.active,curl -s http://192.168.137.102/status | grep Active | awk '{print $NF}' ##被监控的nginxIP地址
UserParameter=nginx.server,curl -s http://127.0.0.1/status |awk NR==3 | awk '{print $1}' ##取出status的第三行第一字符
UserParameter=nginx.accept,curl -s http://127.0.0.1/status |awk NR==3 | awk '{print $2}'
UserParameter=nginx.handled,curl -s http://127.0.0.1/status |awk NR==3 | awk '{print $3}'
[root@server2 zabbix_agentd.d]# /etc/init.d/zabbix-agent restart
[root@server2 zabbix_agentd.d]# vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.html index.htm;
}
location /tatus {
stub_status on;
access_log off;
}
[root@server2 ~]# nginx -t
[root@server2 ~]# nginx -s reload
##server测试是否能拿到数据
[root@Server3 ~]# zabbix_get -s 192.168.137.102 -k nginx.server
20
[root@Server3 ~]# zabbix_get -s 192.168.137.102 -k nginx.accept
5
[root@Server3 ~]# zabbix_get -s 192.168.137.102 -k nginx.handled
9
3.添加监控项并创建图形