标签:reading code 服务 sbin 操作 http ESS get int
使用Nginx -V可以查看nginx是否将模块·http_stub_status_module`编译进包中:
启用Nginx status模块
location /nginx_status { stub_status on; access_log off; allow 127.0.0.1; allow 192.168.55.36/24; deny all; }
然后使用浏览器或者curl指令查看nginx status:
curl http://127.0.0.1/ngx_status
Active connections: 11921 server accepts handled requests 11989 11989 11991 Reading: 0 Writing: 7 Waiting: 42
编写nginx脚本
#!/bin/bash #=========================> HOST="127.0.0.1" PORT="80" # 检测nginx进程是否存在 function ping { /sbin/pidof nginx | wc -l } # 检测nginx性能 function active { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Active‘ | awk ‘{print $NF}‘ } function reading { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Reading‘ | awk ‘{print $2}‘ } function writing { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Writing‘ | awk ‘{print $4}‘ } function waiting { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| grep ‘Waiting‘ | awk ‘{print $6}‘ } function accepts { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $1}‘ } function handled { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $2}‘ } function requests { /usr/bin/curl "http://$HOST:$PORT/ngx_status/" 2>/dev/null| awk NR==3 | awk ‘{print $3}‘ } $1
zabbix客户端配置
将自定义的UserParameter加入配置文件,然后重启agentd,如下:
UserParameter=nginx.status[*],/usr/local/zabbix-3.0.0/scripts/ngx-status.sh $1
服务端测试通过zabbix_get工具
zabbix_get -s 192.168.55.40 -k ‘nginx.status[accepts]‘
剩下的便是管理页面上的操作了
标签:reading code 服务 sbin 操作 http ESS get int
原文地址:https://www.cnblogs.com/HByang/p/9263437.html