使用nginx-prometheus-exporter 监控nginx
因为nginx 已经提供了stub_status 模块,一般我们可以基于此进行监控,目前官方提供了一个exporter
尽管有一些限制(web必须使用8080)。以下是一个简单的学习使用
环境准备
- docker-compose 文件
注意使用了ranadeeppolavarapu 提供的nginx 镜像(很方便,可以学习各种nginx 插件的使用)
version: "3"
services:
httpservice:
image: ranadeeppolavarapu/nginx-http3:edge
volumes:
- "./nginx.conf:/etc/nginx/nginx.conf"
- "./h3.nginx.conf:/etc/nginx/conf.d/h3.nginx.conf"
- "./status.conf:/etc/nginx/conf.d/status.conf"
- "./localhost.crt:/etc/ssl/localhost.crt"
- "./localhost.key:/etc/ssl/localhost.key"
ports:
- "443:443/tcp"
- "443:443/udp"
- "8080:8080"
prome:
image: nginx/nginx-prometheus-exporter:0.8.0
command: -nginx.scrape-uri http://httpservice:8080/stub_status
ports:
- "9113:9113"
- nginx 配置
nginx.conf:
核心部分主要是关于nginx 的配置加载
include /etc/nginx/conf.d/*.conf;
status.conf:
server {
listen 8080;
server_name localhost;
gzip on;
gzip_http_version 1.1;
gzip_vary on;
gzip_comp_level 6;
gzip_proxied any;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/javascript;
brotli_static on;
brotli on;
brotli_types text/plain text/css application/json application/javascript application/x-javascript text/javascript;
brotli_comp_level 4;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location = /stub_status {
stub_status;
}
}
- 启动访问效果
exporter信息
说明
nginx-prometheus-exporter 的实现并不是很难,可以学习下实现,而且目前官方也提供了grafana 的dashboard 配置,但是总的来说监控点
还是太弱了
参考资料
https://github.com/nginxinc/nginx-prometheus-exporter
http://nginx.org/en/docs/http/ngx_http_stub_status_module.html
https://github.com/RanadeepPolavarapu/docker-nginx-http3
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2019-08-29 chart.xkcd 可绘制粗略,开通,手绘样式的图表库
2018-08-29 apache flink kubernetes 运行试用
2018-08-29 apache flink docker-compose 运行试用