NGINX Prometheus Exporter是一个用于监控NGINX或NGINX Plus的Prometheus导出器。它能够从NGINX或NGINX Plus收集性能指标,将其转换为Prometheus兼容的格式,并通过HTTP服务器暴露这些指标,以便Prometheus进行抓取和监控。
NGINX配置要求
对于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; } }
使用docker run命令
监控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
使用docker-compose配置
yamlversion: '3' services: nginx-exporter: image: nginx/nginx-prometheus-exporter:latest container_name: nginx-exporter restart: always ports: - "9113:9113" command: - --nginx.scrape-uri=http://nginx:8080/stub_status 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 | http://127.0.0.1:8080/stub_status |
--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=http://nginx:8080/stub_status \ -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 | 空闲客户端连接数 |
HTTP指标
| 名称 | 类型 | 描述 |
|---|---|---|
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: 开发分支最新构建项目源码: https://github.com/nginx/nginx-prometheus-exporter
问题反馈: https://github.com/nginx/nginx-prometheus-exporter/issues
本项目采用Apache License 2.0许可证。详情请参见https://github.com/nginx/nginx-prometheus-exporter/blob/main/LICENSE%E6%96%87%E4%BB%B6%E3%80%82
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 版本下载页面。



探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
manifest unknown
no matching manifest(架构)
invalid tar header(解压)
TLS 证书失败
DNS 超时
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务