NGINX Prometheus Exporter for NGINX and NGINX Plus
NGINX Prometheus Exporter is a monitoring tool designed to collect and expose metrics from NGINX and NGINX Plus servers for Prometheus. It converts these metrics into appropriate types and makes them available via an HTTP server, enabling effective monitoring and analysis.
Key Features:
Support for NGINX and NGINX Plus: Works seamlessly with both NGINX OSS and NGINX Plus.
Metric Conversion: Converts NGINX/NGINX Plus metrics into Prometheus-compatible formats.
HTTP Exposure: Exposes metrics via an HTTP server to facilitate easy scraping by Prometheus.
Command-Line Configuration: Adjustable settings through command-line arguments for flexibility.
Unix Domain Sockets: Supports scraping metrics using Unix domain sockets for enhanced security.
Audience & Benefit:
Ideal for DevOps engineers, system administrators, and anyone responsible for monitoring NGINX-based infrastructure. This tool provides actionable insights to troubleshoot issues, optimize performance, and ensure high availability of web services.
Install via winget for straightforward setup and integration into your existing Prometheus ecosystem.
README
NGINX Prometheus Exporter
NGINX Prometheus exporter makes it possible to monitor NGINX or NGINX Plus using Prometheus.
NGINX exposes a handful of metrics via the stub_status
page. NGINX
Plus provides a richer set of metrics via the
API 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 Prometheus.
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 NGINX Ingress
Controller 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 stub_status
page at /stub_status on port 8080.
For NGINX Plus, expose the API at /api on port
8080.
Configure Prometheus to scrape metrics from the server with the exporter. Note that the default scrape port of the
exporter is 9113 and the default metrics path -- /metrics.
Running the Exporter in a Docker Container
To start the exporter we use the docker run command.
To export NGINX metrics, run:
docker run -p 9113:9113 nginx/nginx-prometheus-exporter:1.5.0 --nginx.scrape-uri=http://:8080/stub_status
where `` is the IP address/DNS name, through which NGINX is available.
To export NGINX Plus metrics, run:
docker run -p 9113:9113 nginx/nginx-prometheus-exporter:1.5.0 --nginx.plus --nginx.scrape-uri=http://:8080/api
where `` is the IP address/DNS name, through which NGINX Plus is available.
where `` 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
usage: nginx-prometheus-exporter []
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
> Note: for the state metric, 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
server, upstream
nginxplus_upstream_server_unavail
Counter
How many times the server became unavailable for client requests (state 'unavail') due to the number of unsuccessful attempts reaching the max_fails threshold
server, upstream
nginxplus_upstream_server_header_time
Gauge
Average time to get the response header from the server
server, upstream
nginxplus_upstream_server_response_time
Gauge
Average time to get the full response from the server
server, upstream
nginxplus_upstream_server_health_checks_checks
Counter
Total health check requests
server, upstream
nginxplus_upstream_server_health_checks_fails
Counter
Failed health checks
server, upstream
nginxplus_upstream_server_health_checks_unhealthy
Counter
How many times the server became unhealthy (state 'unhealthy')
server, upstream
nginxplus_upstream_server_ssl_handshakes
Counter
Successful SSL handshakes
server, upstream
nginxplus_upstream_server_ssl_handshakes_failed
Counter
Failed SSL handshakes
server, upstream
nginxplus_upstream_server_ssl_session_reuses
Counter
Session reuses during SSL handshake
server, upstream
nginxplus_upstream_keepalive
Gauge
Idle keepalive connections
upstream
nginxplus_upstream_zombies
Gauge
Servers removed from the group but still processing active client requests
> Note: for the state metric, the string values are converted to float64 using the following rule: "up" -> 1.0,
> "down" -> 3.0, "unavail" –> 4.0, "checking" –> 5.0, "unhealthy" -> 6.0.
Name
Type
Description
Labels
nginxplus_stream_upstream_server_state
Gauge
Current state
server, upstream
nginxplus_stream_upstream_server_active
Gauge
Active connections
server , upstream
nginxplus_stream_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_stream_upstream_server_connections
Counter
Total number of client connections forwarded to this server
server, upstream
nginxplus_stream_upstream_server_connect_time
Gauge
Average time to connect to the upstream server
server, upstream
nginxplus_stream_upstream_server_first_byte_time
Gauge
Average time to receive the first byte of data
server, upstream
nginxplus_stream_upstream_server_response_time
Gauge
Average time to receive the last byte of data
server, upstream
nginxplus_stream_upstream_server_sent
Counter
Bytes sent to this server
server, upstream
nginxplus_stream_upstream_server_received
Counter
Bytes received from this server
server, upstream
nginxplus_stream_upstream_server_fails
Counter
Number of unsuccessful attempts to communicate with the server
server, upstream
nginxplus_stream_upstream_server_unavail
Counter
How many times the server became unavailable for client connections (state 'unavail') due to the number of unsuccessful attempts reaching the max_fails threshold
The current number of client requests that are currently being processed
id, pid
Connect to the /metrics page of the running exporter to see the complete list of metrics along with their
descriptions. Note: to see server zones related metrics you must configure status
zones and to see upstream related metrics you
must configure upstreams with a shared memory zone.
Troubleshooting
The exporter logs errors to the standard output. When using Docker, if the exporter doesn’t work as expected, check its
logs using docker logs command.
As an alternative, you can choose the edge version built from the latest commit
from the main branch. The edge version is useful for experimenting with new features that are not yet published in a
stable release.
Binaries
We publish the binaries for multiple Operating Systems and architectures on the GitHub releases page.
Homebrew
You can add the NGINX homebrew tap with
brew tap nginx/tap
and then install the formula with
brew install nginx-prometheus-exporter
Snap
You can install the NGINX Prometheus Exporter from the Snap Store.
We’d like to hear your feedback! If you have any suggestions or experience issues with the NGINX Prometheus Exporter,
please create an issue or send a pull request on GitHub. You can contact us on the NGINX Community Forums.
Contributing
If you'd like to contribute to the project, please read our Contributing guide.
Support
The commercial support is available for NGINX Plus customers when the NGINX Prometheus Exporter is used with NGINX
Ingress Controller.