nginx的安装与使用这里不再演示
添加nginx状态的状态模块:
状态模块内容如下:
location /status { stub_status on; access_log off; allow 10.0.0.0/24; deny all; }
修改nginx
端口并重启
测试:http://192.168.56.11:8080/status
[root@web01 ~]# curl http://10.0.0.9:8080/status/ Active connections: 1 server accepts handled requests 1 1 1 Reading: 0 Writing: 1 Waiting: 0
解释说明:使用zabbix来监控活动连接数,通过status状态模块为前提
我们现在命令取出我们想要的值,例如:
[root@web01 ~]# curl http://10.0.0.9:8080/status/|grep Active|awk -F "[ ]" '{print $3}'
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 97 0 97 0 0 166k 0 --:--:-- --:--:-- --:--:-- 0
1
显示监控的活动连接数为1
#提示: 如果想要加自定义监控项,不要在配置文件中写入,可以在Include
里面定义的目录写上
只要我们写在Include
目录下,都可以识别到
[root@web01 ~]# cd /application/zabbix/etc/zabbix_agentd.conf.d/ [root@web01 zabbix_agentd.conf.d]# ll 总用量 8 -rw-r--r-- 1 1001 1001 121 9月 23 19:38 userparameter_mysql.conf -rw-r--r-- 1 root root 105 9月 24 17:23 userparameter_nginx.conf [root@web01 zabbix_agentd.conf.d]# vim userparameter_nginx.conf UserParameter=nginx.active,/usr/bin/curl -s http://10.0.0.9:8080/status|grep Active|awk -F "[ ]" '{print $3}'
说明:
参数:UserParameter,+定义的key: nginx.active +command
zabbix agentd会调用这个脚本
修改完之后重启zabbix-agentd
zabbix服务端使用zabbix-get进行测试
[root@ZabbixServer yum.repos.d]# /application/zabbix/bin/zabbix_get -s 10.0.0.9 -k "nginx.active" 1
结果返回1,说明已经建立一个连接。
接下来,在zabbix-web上添加item
创建图形:
效果:
测试触发器
功能陈述:
当nginx连接数超出10个进行触发报警显示严重。
前面已经建立了nginx.active监控项了,现在创建触发器
依赖关系可以不添加任何内容,这里只做测试,更新即可。
现在访问测试:
[root@ZabbixServer ~]# ab -c 100 -n 10000 http://10.0.0.9:8080/ This is ApacheBench, Version 2.3 <$Revision: 655654 $> Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 10.0.0.9 (be patient) Completed 1000 requests Completed 2000 requests Completed 3000 requests Completed 4000 requests Completed 5000 requests Completed 6000 requests Completed 7000 requests Completed 8000 requests Completed 9000 requests Completed 10000 requests Finished 10000 requests Server Software: nginx/1.10.2 Server Hostname: 10.0.0.9 Server Port: 8080
报警页面显示效果:
如果想加入报警提示音的话,点击用户管理界面,将用户提示音加进去即可。