NGINX Prometheus Exporter用于收集并导出NGINX与NGINX Plus的监控指标,供Prometheus采集以实现对其运行状态的监控。
NGINX Prometheus Exporter
NGINX Prometheus exporter makes it possible to monitor NGINX or NGINX Plus using Prometheus.
Table of Contents
- Overview
- Getting Started
- A Note about NGINX Ingress Controller
- Prerequisites
- Running the Exporter in a Docker Container
- Running the Exporter Binary
- Usage
- Command-line Arguments
- Exported Metrics
- Common metrics
- Metrics for NGINX OSS
- Stub status metrics
- Metrics for NGINX Plus
- Connections
- HTTP
- SSL
- HTTP Server Zones
- Stream Server Zones
- HTTP Upstreams
- Stream Upstreams
- Stream Zone Sync
- Location Zones
- Resolver
- HTTP Requests Rate Limiting
- HTTP Connections Limiting
- Stream Connections Limiting
- Cache
- Worker
- License
- Troubleshooting
- Releases
- Docker images
- Binaries
- Homebrew
- Scoop
- Nix
- Building the Exporter
- Building the Docker Image
- Building the Binary
- Grafana Dashboard
- SBOM (Software Bill of Materials)
- Binaries
- Docker Image
- Provenance
- Contacts
- Contributing
- Support
- License
Overview
https://nginx.org exposes a handful of metrics via the https://nginx.org/en/docs/http/ngx_http_stub_status_module.html#stub_status. NGINX Plus provides a richer set of metrics via the https://nginx.org/en/docs/http/ngx_http_api_module.html and the monitoring dashboard. NGINX Prometheus exporter fetches the metrics from a single NGINX or NGINX Plus, converts the metrics into appropriate Prometheus metrics types and finally exposes them via an HTTP server to be collected by https://prometheus.io/.
Getting Started
In this section, we show how to quickly run NGINX Prometheus Exporter for NGINX or NGINX Plus.
A Note about NGINX Ingress Controller
If you’d like to use the NGINX Prometheus Exporter with https://github.com/nginx/kubernetes-ingress/ for Kubernetes, see this doc for the installation instructions.
Prerequisites
We assume that you have already installed Prometheus and NGINX or NGINX Plus. Additionally, you need to:
- Expose the built-in metrics in NGINX/NGINX Plus:
- For NGINX, expose the https://nginx.org/en/docs/http/ngx_http_stub_status_module.html#stub_status at
/stub_statuson port8080. - For NGINX Plus, expose the https://nginx.org/en/docs/http/ngx_http_api_module.html#api at
/apion port8080.
- For NGINX, expose the https://nginx.org/en/docs/http/ngx_http_stub_status_module.html#stub_status at
- Configure Prometheus to scrape metrics from the server with the exporter. Note that the default scrape port of the
exporter is
9113and the default metrics path --/metrics.
Running the Exporter in a Docker Container
To start the exporter we use the https://docs.docker.com/engine/reference/run/ command.
-
To export NGINX metrics, run:
consoledocker run -p 9113:9113 nginx/nginx-prometheus-exporter:1.5.1 --nginx.scrape-uri=http://<nginx>:8080/stub_statuswhere
<nginx>is the IP address/DNS name, through which NGINX is available. -
To export NGINX Plus metrics, run:
consoledocker run -p 9113:9113 nginx/nginx-prometheus-exporter:1.5.1 --nginx.plus --nginx.scrape-uri=http://<nginx-plus>:8080/apiwhere
<nginx-plus>is the IP address/DNS name, through which NGINX Plus is available.
Running the Exporter Binary
-
To export NGINX metrics, run:
consolenginx-prometheus-exporter --nginx.scrape-uri=http://<nginx>:8080/stub_statuswhere
<nginx>is the IP address/DNS name, through which NGINX is available. -
To export NGINX Plus metrics:
consolenginx-prometheus-exporter --nginx.plus --nginx.scrape-uri=http://<nginx-plus>:8080/apiwhere
<nginx-plus>is the IP address/DNS name, through which NGINX Plus is available. -
To scrape NGINX metrics with unix domain sockets, run:
consolenginx-prometheus-exporter --nginx.scrape-uri=unix:<nginx>:/stub_statuswhere
<nginx>is the path to unix domain socket, through which NGINX stub status is available.
Note. The nginx-prometheus-exporter is not a daemon. To run the exporter as a system service (daemon), you can
follow the example in examples/systemd. Alternatively, you can run the exporter
in a Docker container.
Usage
Command-line Arguments
consoleusage: nginx-prometheus-exporter [<flags>] Flags: -h, --[no-]help Show context-sensitive help (also try --help-long and --help-man). --[no-]web.systemd-socket Use systemd socket activation listeners instead of port listeners (Linux only). ($SYSTEMD_SOCKET) --web.listen-address=:9113 ... Addresses on which to expose metrics and web interface. Repeatable for multiple addresses. ($LISTEN_ADDRESS) --web.config.file="" Path to configuration file that can enable TLS or authentication. See: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md ($CONFIG_FILE) --web.telemetry-path="/metrics" Path under which to expose metrics. ($TELEMETRY_PATH) --[no-]nginx.plus Start the exporter for NGINX Plus. By default, the exporter is started for NGINX. ($NGINX_PLUS) --nginx.scrape-uri=http://127.0.0.1:8080/stub_status ... A URI or unix domain socket path for scraping NGINX or NGINX Plus metrics. For NGINX, the stub_status page must be available through the URI. For NGINX Plus -- the API. Repeatable for multiple URIs. ($SCRAPE_URI) --[no-]nginx.ssl-verify Perform SSL certificate verification. ($SSL_VERIFY) --nginx.ssl-ca-cert="" Path to the PEM encoded CA certificate file used to validate the servers SSL certificate. ($SSL_CA_CERT) --nginx.ssl-client-cert="" Path to the PEM encoded client certificate file to use when connecting to the server. ($SSL_CLIENT_CERT) --nginx.ssl-client-key="" Path to the PEM encoded client certificate key file to use when connecting to the server. ($SSL_CLIENT_KEY) --[no-]nginx.proxy-protocol Pass proxy protocol payload to nginx listeners. ($PROXY_PROTOCOL) --nginx.timeout=5s A timeout for scraping metrics from NGINX or NGINX Plus. ($TIMEOUT) --prometheus.const-label=PROMETHEUS.CONST-LABEL ... Label that will be used in every metric. Format is label=value. It can be repeated multiple times. ($CONST_LABELS) --log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error] --log.format=logfmt Output format of log messages. One of: [logfmt, json] --[no-]version Show application version.
Exported Metrics
Common metrics
| Name | Type | Description | Labels |
|---|---|---|---|
nginx_exporter_build_info | Gauge | Shows the exporter build information. | branch, goarch, goos, goversion, revision, tags and version |
promhttp_metric_handler_requests_total | Counter | Total number of scrapes by HTTP status code. | code (the HTTP status code) |
promhttp_metric_handler_requests_in_flight | Gauge | Current number of scrapes being served. | [] |
go_* | Multiple | Go runtime metrics. | [] |
Metrics for NGINX OSS
| Name | Type | Description | Labels |
|---|---|---|---|
nginx_up | Gauge | Shows the status of the last metric scrape: 1 for a successful scrape and 0 for a failed one | [] |
https://nginx.org/en/docs/http/ngx_http_stub_status_module.html
| Name | Type | Description | Labels |
|---|---|---|---|
nginx_connections_accepted | Counter | Accepted client connections. | [] |
nginx_connections_active | Gauge | Active client connections. | [] |
nginx_connections_handled | Counter | Handled client connections. | [] |
nginx_connections_reading | Gauge | Connections where NGINX is reading the request header. | [] |
nginx_connections_waiting | Gauge | Idle client connections. | [] |
nginx_connections_writing | Gauge | Connections where NGINX is writing the response back to the client. | [] |
nginx_http_requests_total | Counter | Total http requests. | [] |
Metrics for NGINX Plus
| Name | Type | Description | Labels |
|---|---|---|---|
nginxplus_up | Gauge | Shows the status of the last metric scrape: 1 for a successful scrape and 0 for a failed one | [] |
https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_connections
| Name | Type | Description | Labels |
|---|---|---|---|
nginxplus_connections_accepted | Counter | Accepted client connections | [] |
nginxplus_connections_active | Gauge | Active client connections | [] |
nginxplus_connections_dropped | Counter | Dropped client connections dropped | [] |
nginxplus_connections_idle | Gauge | Idle client connections | [] |
https://nginx.org/en/docs/http/ngx_http_api_module.html#http_
| Name | Type | Description | Labels |
|---|---|---|---|
nginxplus_http_requests_total | Counter | Total http requests | [] |
nginxplus_http_requests_current | Gauge | Current http requests | [] |
https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_ssl_object
| Name | Type | Description | Labels |
|---|---|---|---|
nginxplus_ssl_handshakes | Counter | Successful SSL handshakes | [] |
nginxplus_ssl_handshakes_failed | Counter | Failed SSL handshakes | [] |
nginxplus_ssl_session_reuses | Counter | Session reuses during SSL handshake | [] |
https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_http_server_zone
| Name | Type | Description | Labels |
|---|---|---|---|
nginxplus_server_zone_processing | Gauge | Client requests that are currently being processed | server_zone |
nginxplus_server_zone_requests | Counter | Total client requests | server_zone |
nginxplus_server_zone_responses | Counter | Total responses sent to clients | code (the response status code. The values are: 1xx, 2xx, 3xx, 4xx and 5xx), server_zone |
nginxplus_server_zone_responses_codes | Counter | Total responses sent to clients by code | code (the response status code. The possible values are available on the NGINX Wiki), server_zone |
nginxplus_server_zone_discarded | Counter | Requests completed without sending a response | server_zone |
nginxplus_server_zone_received | Counter | Bytes received from clients | server_zone |
nginxplus_server_zone_sent | Counter | Bytes sent to clients | server_zone |
nginxplus_server_ssl_handshakes | Counter | Successful SSL handshakes | server_zone |
nginxplus_server_ssl_handshakes_failed | Counter | Failed SSL handshakes | server_zone |
nginxplus_server_ssl_session_reuses | Counter | Session reuses during SSL handshake | server_zone |
https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_stream_server_zone
| Name | Type | Description | Labels |
|---|---|---|---|
nginxplus_stream_server_zone_processing | Gauge | Client connections that are currently being processed | server_zone |
nginxplus_stream_server_zone_connections | Counter | Total connections | server_zone |
nginxplus_stream_server_zone_sessions | Counter | Total sessions completed | code (the response status code. The values are: 2xx, 4xx, and 5xx), server_zone |
nginxplus_stream_server_zone_discarded | Counter | Connections completed without creating a session | server_zone |
nginxplus_stream_server_zone_received | Counter | Bytes received from clients | server_zone |
nginxplus_stream_server_zone_sent | Counter | Bytes sent to clients | server_zone |
nginxplus_stream_server_ssl_handshakes | Counter | Successful SSL handshakes | server_zone |
nginxplus_stream_server_ssl_handshakes_failed | Counter | Failed SSL handshakes | server_zone |
nginxplus_stream_server_ssl_session_reuses | Counter | Session reuses during SSL handshake | server_zone |
https://nginx.org/en/docs/http/ngx_http_api_module.html#def_nginx_http_upstream
Note: for the
statemetric, the string values are converted to float64 using the following rule:"up"->1.0,"draining"->2.0,"down"->3.0,"unavail"–>4.0,"checking"–>5.0,"unhealthy"->6.0.
| Name | Type | Description | Labels |
|---|---|---|---|
nginxplus_upstream_server_state | Gauge | Current state | server, upstream |
nginxplus_upstream_server_active | Gauge | Active connections | server, upstream |
nginxplus_upstream_server_limit | Gauge | Limit for connections which corresponds to the max_conns parameter of the upstream server. Zero value means there is no limit | server, upstream |
nginxplus_upstream_server_requests | Counter | Total client requests | server, upstream |
nginxplus_upstream_server_responses | Counter | Total responses sent to clients | code (the response status code. The values are: 1xx, 2xx, 3xx, 4xx and 5xx), server, upstream |
nginxplus_upstream_server_responses_codes | Counter | Total responses sent to clients by code | code (the response status code. The possible values are available on the NGINX Wiki), server, upstream |
nginxplus_upstream_server_sent | Counter | Bytes sent to this server | server, upstream |
nginxplus_upstream_server_received | Counter | Bytes received to this server | server, upstream |
nginxplus_upstream_server_fails | Counter | Number of unsuccessful attempts to communicate with the server |
nginx 命名空间的其他可用镜像:
镜像拉取方式
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
轩辕镜像加速拉取命令点我查看更多 nginx-prometheus-exporter 镜像标签
DockerHub 原生拉取命令
用户好评
来自真实用户的反馈,见证轩辕镜像的优质服务