编辑nginx的配置文件nging
#配置ngx_status
location /nginx_status
{ stub_status on; access_log off; }
#重启nginx
# service nginx restart
#打开status页面
curl http://127.0.0.1/nginx_status Active connections: 11 server accepts handled requests 154768 154768 163529 Reading: 0 Writing: 1 Waiting: 10
#zabbix客户端设置
#!/bin/bash BKUP_DATE=`/bin/date +%Y%m%d` LOG="/tmp/webstatus.log" HOST=127.0.0.1 PORT="80" # Functions to return nginx stats function active { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| grep 'Active' | awk '{print $NF}' } function reading { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| grep 'Reading' | awk '{print $2}' } function writing { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| grep 'Writing' | awk '{print $4}' } function waiting { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| grep 'Waiting' | awk '{print $6}' } function accepts { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| awk NR==3 | awk '{print $1}' } function handled { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| awk NR==3 | awk '{print $2}' } function requests { /usr/bin/curl "http://$HOST:$PORT/nginx_status" 2>/dev/null| awk NR==3 | awk '{print $3}' } # Run the requested function $1
#zabbix_agentd.conf设置
#nginx-status #接受的请求 UserParameter=nginx.accepts,/usr/local/zabbix/scripts/nginx_status.sh accepts #成功创建了多少次握手 UserParameter=nginx.handled,/usr/local/zabbix/scripts/nginx_status.sh handled #总共处理了的请求 UserParameter=nginx.requests,/usr/local/zabbix/scripts/nginx_status.sh requests #对后端发起的活动连接数 UserParameter=nginx.connections.active,/usr/local/zabbix/scripts/nginx_status.sh active #读取客户端的连接数 UserParameter=nginx.connections.reading,/usr/local/zabbix/scripts/nginx_status.sh reading #响应数据到客户端的数量 UserParameter=nginx.connections.writing,/usr/local/zabbix/scripts/nginx_status.sh writing #Nginx 已经处理完正在等候下一次请求指令的驻留连接 UserParameter=nginx.connections.waiting,/usr/local/zabbix/scripts/nginx_status.sh waiting
zabbix管理后台配置
导入nginx-status模板
进入后台->configuration->templates->import(右侧)->选择nginx-status模板->最后点击import。至此nginx-status模板已经导入到zabbix中