“Zabbix监控nginx”的版本间的差异
跳到导航
跳到搜索
(未显示同一用户的12个中间版本) | |||
第1行: | 第1行: | ||
+ | [[category:zabbix]] | ||
=office= | =office= | ||
<pre> | <pre> | ||
第54行: | 第55行: | ||
告警项目:web.page.get["localhost","basic_status","80"] | 告警项目:web.page.get["localhost","basic_status","80"] | ||
+ | 最后添加官方模板 Template App Nginx by Zabbix agent | ||
</pre> | </pre> | ||
+ | =3rd_party= | ||
+ | 官方推荐 | ||
+ | https://github.com/mjwtc0722/zabbix-nginx-status | ||
+ | |||
+ | |||
+ | <pre> | ||
+ | |||
+ | 注意 这些是手工操作 建议用批量例如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 | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | </pre> | ||
+ | = References = | ||
+ | |||
+ | [https://www.zabbix.com/integrations/nginx Nginx monitoring 官方 ] | ||
+ | |||
+ | [https://blog.csdn.net/tladagio/article/details/103101807 Zabbix 4.4(五)zabbix监控nginx(自定义nginx监控选项)] | ||
[https://blog.csdn.net/qq_34556414/article/details/105725187 Nginx http_stub_status_module状态查看模块] | [https://blog.csdn.net/qq_34556414/article/details/105725187 Nginx http_stub_status_module状态查看模块] | ||
− | [https://www. | + | [https://blog.csdn.net/weixin_43279032/article/details/116709023 zabbix之监控nginx的活动连接数] |
+ | |||
+ | [https://blog.z0ukun.com/?p=1472 zabbix4.4监控案例之Nginx监控] | ||
+ | |||
+ | [https://blog.csdn.net/weixin_42708432/article/details/109150647 Zabbix5.0之监控Nginx good] | ||
+ | |||
+ | [https://www.jianshu.com/p/c6734617a08c Zabbix5.0监控Nginx] | ||
+ | |||
+ | [https://www.cxybb.com/article/weixin_42708432/109150647 Zabbix5.0之监控Nginx_傻笑zz的博客-程序员宝宝 ] | ||
+ | |||
+ | |||
+ | [http://www.ttlsa.com/zabbix/zabbix-monitor-nginx-performance/ Zabbix监控nginx性能(113)] |
2021年10月21日 (四) 11:36的最新版本
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
References
Zabbix 4.4(五)zabbix监控nginx(自定义nginx监控选项)
Nginx http_stub_status_module状态查看模块