NGINX Prometheus Exporter用于收集并导出NGINX与NGINX Plus的监控指标,供Prometheus采集以实现对其运行状态的监控。
收藏数: 50
下载次数: 86636152
类型:
nginx/nginx-prometheus-exporterNGINX Prometheus Exporter是一个用于监控NGINX或NGINX Plus的Prometheus导出器。它能够从NGINX或NGINX Plus收集性能指标,将其转换为Prometheus兼容的格式,并通过HTTP服务器暴露这些指标,以便Prometheus进行抓取和监控。
对于NGINX开源版:
nginxserver { listen 8080; location /stub_status { stub_status; allow 127.0.0.1; # 允许 exporter 访问 deny all; } }
对于NGINX Plus:
nginxserver { listen 8080; location /api { api; allow 127.0.0.1; # 允许 exporter 访问 deny all; } }
监控NGINX开源版:
bashdocker run -d -p 9113:9113 --name nginx-exporter \ nginx/nginx-prometheus-exporter:latest \ --nginx.scrape-uri=http://<nginx-ip>:8080/stub_status
监控NGINX Plus:
bashdocker run -d -p 9113:9113 --name nginx-exporter \ nginx/nginx-prometheus-exporter:latest \ --nginx.plus --nginx.scrape-uri=http://<nginx-plus-ip>:8080/api
使用Unix域套接字:
bashdocker run -d -p 9113:9113 --name nginx-exporter \ -v /var/run/nginx.sock:/var/run/nginx.sock \ nginx/nginx-prometheus-exporter:latest \ --nginx.scrape-uri=unix:/var/run/nginx.sock:/stub_status
yamlversion: '3' services: nginx-exporter: image: nginx/nginx-prometheus-exporter:latest container_name: nginx-exporter restart: always ports: - "9113:9113" command: - --nginx.scrape-uri=[***] depends_on: - nginx networks: - monitoring-network nginx: image: nginx:latest container_name: nginx restart: always ports: - "80:80" volumes: - ./nginx.conf:/etc/nginx/nginx.conf networks: - monitoring-network networks: monitoring-network: driver: bridge
| 参数 | 环境变量 | 描述 | 默认值 |
|---|---|---|---|
--web.listen-address | LISTEN_ADDRESS | 暴露指标的地址 | :9113 |
--web.telemetry-path | TELEMETRY_PATH | 指标路径 | /metrics |
--web.config.file | CONFIG_FILE | TLS和认证配置文件路径 | "" |
--nginx.plus | NGINX_PLUS | 是否监控NGINX Plus | false |
--nginx.scrape-uri | SCRAPE_URI | NGINX指标抓取URI | [***] |
--nginx.ssl-verify | SSL_VERIFY | 是否验证SSL证书 | true |
--nginx.ssl-ca-cert | SSL_CA_CERT | CA证书路径 | "" |
--nginx.ssl-client-cert | SSL_CLIENT_CERT | 客户端证书路径 | "" |
--nginx.ssl-client-key | SSL_CLIENT_KEY | 客户端密钥路径 | "" |
--nginx.proxy-protocol | PROXY_PROTOCOL | 是否传递代理协议 | false |
--nginx.timeout | TIMEOUT | 指标抓取超时 | 5s |
--prometheus.const-label | CONST_LABELS | 所有指标的常量标签 | "" |
--log.level | - | 日志级别 | info |
--log.format | - | 日志格式 | logfmt |
bashdocker run -d -p 9113:9113 --name nginx-exporter \ -e LISTEN_ADDRESS=:9113 \ -e NGINX_PLUS=false \ -e SCRAPE_URI=[***] \ -e TIMEOUT=10s \ nginx/nginx-prometheus-exporter:latest
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
nginx_exporter_build_info | Gauge | 导出器构建信息 | branch, goarch, goos, goversion, revision, tags, version |
promhttp_metric_handler_requests_total | Counter | 按HTTP状态码的抓取总数 | code |
promhttp_metric_handler_requests_in_flight | Gauge | 当前正在处理的抓取请求数 | - |
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
nginx_up | Gauge | 最后一次指标抓取状态 (1=成功, 0=失败) | - |
nginx_connections_accepted | Counter | 接受的客户端连接数 | - |
nginx_connections_active | Gauge | 活跃的客户端连接数 | - |
nginx_connections_handled | Counter | 已处理的客户端连接数 | - |
nginx_connections_reading | Gauge | 读取请求头的连接数 | - |
nginx_connections_waiting | Gauge | 空闲客户端连接数 | - |
nginx_connections_writing | Gauge | 写入响应的连接数 | - |
nginx_http_requests_total | Counter | HTTP请求总数 | - |
除上述指标外,NGINX Plus还提供以下额外指标:
| 名称 | 类型 | 描述 |
|---|---|---|
nginxplus_connections_accepted | Counter | 接受的客户端连接数 |
nginxplus_connections_active | Gauge | 活跃的客户端连接数 |
nginxplus_connections_dropped | Counter | 丢弃的客户端连接数 |
nginxplus_connections_idle | Gauge | 空闲客户端连接数 |
| 名称 | 类型 | 描述 |
|---|---|---|
nginxplus_http_requests_total | Counter | HTTP请求总数 |
nginxplus_http_requests_current | Gauge | 当前HTTP请求数 |
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
nginxplus_server_zone_requests | Counter | 客户端请求总数 | server_zone |
nginxplus_server_zone_responses | Counter | 客户端响应总数 | code, server_zone |
nginxplus_server_zone_received | Counter | 从客户端接收的字节数 | server_zone |
nginxplus_server_zone_sent | Counter | 发送给客户端的字节数 | server_zone |
| 名称 | 类型 | 描述 | 标签 |
|---|---|---|---|
nginxplus_upstream_server_state | Gauge | 上游服务器状态 | server, upstream |
nginxplus_upstream_server_active | Gauge | 活跃连接数 | server, upstream |
nginxplus_upstream_server_requests | Counter | 请求总数 | server, upstream |
nginxplus_upstream_server_responses | Counter | 响应总数 | code, server, upstream |
在Prometheus配置文件中添加以下内容以抓取NGINX Exporter指标:
yamlscrape_configs: - job_name: 'nginx' static_configs: - targets: ['nginx-exporter:9113']
官方提供的Grafana仪表板可从以下链接获取:
--nginx.ssl-verify=false禁用SSL验证进行测试--log.level=debug获取详细调试日志latest: 最新稳定版本1, 1.5, 1.5.1: 特定版本号main: 开发分支最新构建项目源码: [***]
问题反馈: [***]
本项目采用Apache License 2.0许可证。详情请参见LICENSE文件。
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 版本下载页面。






manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务