zabbix-----监控nginx连接数
1、修改nginx配置文件,在nginx.conf中添加如下内容
1 location /status { 2 stub_status on; 3 access_log off; 4 }
2、加载配置文件,nginx -s reload
3、测试是否生效,执行如下命令:
1 curl -s http://127.0.0.1:80/status 2 3 执行结果: 4 Active connections: 24071 5 server accepts handled requests 6 17846876 17846876 17764748 7 Reading: 0 Writing: 19601 Waiting: 2937
4、通过awk提取需要Active、accepts、handled、requests,测试是否提取成功
1 curl -s http://127.0.0.1:80/status|grep Active|awk -F "[ ]" '{print $3}' 2 curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {'print $1'} 3 curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {'print $2'} 4 curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {'print $3'}
5、zabbix_agent.conf 加入UserParameter,编辑配置文件,找到UserParameter,增加如下内容
1 UserParameter= nginx.active,/usr/bin/curl -s http://127.0.0.1:80/status|grep Active|awk -F "[ ]" '{print $3}' 2 UserParameter= nginx.accepts,/usr/bin/curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {'print $1'} 3 UserParameter= nginx.handled,/usr/bin/curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {'print $2'} 4 UserParameter= nginx.requests,/usr/bin/curl -s http://127.0.0.1:80/status| awk NR==3 | awk -F " " {'print $3'}
6、重启zabbix_agent服务,进入到web监控页面配置
7、配置--->主机--->监控项--->创建监控项,如下图:
8、配置--->主机--->图形--->创建图形,如下图:
9、最终效果如下图: