Zabbix监控nginx
office
nginx -V 2>&1 | grep -o with-http_stub_status_module. Example configuration of Nginx: 直接加在 nginx.conf location = /basic_status { stub_status; allow 127.0.0.1; allow ::1; deny all; } 一般我放的位置 参数不一致 不过官方用过了 爽 可用 server { listen 80 default_server; listen [::]:80 default_server; server_name _; #charset koi8-r; #access_log logs/host.access.log main; #evan location /nginx_stat { stub_status on; access_log off; allow 127.0.0.1; deny all; } #evan 官方模板有 4个图 只有一个 Nginx: Connections by state Nginx: Connections by state 900 200 正常 Nginx: Connections per second 900 200 正常 Nginx: Memory usage 900 200 正常 Nginx: Requests per second 还有报警的要改 可以用 666 告警信息: Nginx: Failed to fetch stub status page (or no data for 30m) 告警项目:web.page.get["localhost","basic_status","80"] 最后添加官方模板 Template App Nginx by Zabbix agent
3rd_party
官方推荐
https://github.com/mjwtc0722/zabbix-nginx-status
注意 这些是手工操作 建议用批量例如ansible #隐私问题 目录不全 openresty/nginx/sbin/nginx -V 2>&1 | grep -o with-http_stub_status_module with-http_stub_status_module 脚本 mkdir -p /etc/zabbix/scripts/ vi /etc/zabbix/scripts/nginx_status.sh #!/bin/bash HOST="127.0.0.1" PORT="80" function proc_num { num=$(pgrep nginx |wc -l) } function active { num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Active' |awk '{print $NF}') } function reading { num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Reading' |awk '{print $2}') } function writing { num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Writing' |awk '{print $4}') } function waiting { num=$(curl -s "http://$HOST:$PORT/nginx_stat" |grep 'Waiting' |awk '{print $6}') } function accepts { num=$(curl -s "http://$HOST:$PORT/nginx_stat" |awk NR==3 |awk '{print $1}') } function handled { num=$(curl -s "http://$HOST:$PORT/nginx_stat" |awk NR==3 |awk '{print $2}') } function requests { num=$(curl -s "http://$HOST:$PORT/nginx_stat" |awk NR==3 |awk '{print $3}') } $1 echo ${num:-0} chmod +x /etc/zabbix/scripts/nginx_status.sh vi /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf UserParameter=nginx.status[*],/etc/zabbix/scripts/nginx_status.sh $1 nginx.conf 加入 server { listen 80 default_server; listen [::]:80 default_server; server_name _; #charset koi8-r; #access_log logs/host.access.log main; #evan location /nginx_stat { stub_status on; access_log off; allow 127.0.0.1; deny all; } #evan location / { root html; index index.ht restart agent 在zabbix web导入模板zbx_nginx_templates.xml并关联主机 以下的可以不看了 curl http://127.0.0.1/nginx_stat Active connections: 4 server accepts handled requests 126582804 126582804 126582907 Reading: 0 Writing: 4 Waiting: 0 不能放在最后呀 虽然没语法错误 server { listen 80; location /nginx_stat { stub_status on; access_log off; allow 127.0.0.1; deny all; } } openresty -t openresty -s reload
R
Zabbix 4.4(五)zabbix监控nginx(自定义nginx监控选项)