MCPcopy
hub / github.com/nginx/nginx-prometheus-exporter

github.com/nginx/nginx-prometheus-exporter @v1.5.1 sqlite

repository ↗ · DeepWiki ↗ · release v1.5.1 ↗
88 symbols 170 edges 8 files 33 documented · 38%
README

OpenSSFScorecard CI FOSSA Status Go Report Card codecov GitHub all releases GitHub release (latest by SemVer) GitHub release (latest SemVer) nginx-prometheus-exporter GitHub go.mod Go version Docker Pulls Docker Image Size (latest semver) Project Status: Active – The project has reached a stable, usable state and is being actively developed.

NGINX Prometheus Exporter

NGINX Prometheus exporter makes it possible to monitor NGINX or NGINX Plus using Prometheus.

Table of Contents

Overview

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:

console docker run -p 9113:9113 nginx/nginx-prometheus-exporter:1.5.1 --nginx.scrape-uri=http://<nginx>:8080/stub_status

where <nginx> is the IP address/DNS name, through which NGINX is available.

  • To export NGINX Plus metrics, run:

console docker run -p 9113:9113 nginx/nginx-prometheus-exporter:1.5.1 --nginx.plus --nginx.scrape-uri=http://<nginx-plus>:8080/api

where <nginx-plus> is the IP address/DNS name, through which NGINX Plus is available.

Running the Exporter Binary

  • To export NGINX metrics, run:

console nginx-prometheus-exporter --nginx.scrape-uri=http://<nginx>:8080/stub_status

where <nginx> is the IP address/DNS name, through which NGINX is available.

  • To export NGINX Plus metrics:

console nginx-prometheus-exporter --nginx.plus --nginx.scrape-uri=http://<nginx-plus>:8080/api

where <nginx-plus> is the IP address/DNS name, through which NGINX Plus is available.

  • To scrape NGINX metrics with unix domain sockets, run:

console nginx-prometheus-exporter --nginx.scrape-uri=unix:<nginx>:/stub_status

where <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

usage: 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 []

Stub status metrics

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 []

Connections

Name Type Description Labels
`nginxplus_conne

Extension points exported contracts — how you extend this code

LabelUpdater (Interface)
LabelUpdater updates the labels of upstream server and server zone metrics. [1 implementers]
collector/nginx_plus.go

Core symbols most depended-on inside this repo

MergeLabels
called by 139
collector/helper.go
newUpstreamServerMetric
called by 61
collector/nginx_plus.go
newServerZoneMetric
called by 53
collector/nginx_plus.go
newLocationZoneMetric
called by 49
collector/nginx_plus.go
newCacheZoneMetric
called by 21
collector/nginx_plus.go
newGlobalMetric
called by 20
collector/helper.go
newStreamUpstreamServerMetric
called by 17
collector/nginx_plus.go
newStreamServerZoneMetric
called by 11
collector/nginx_plus.go

Shape

Method 42
Function 37
Struct 8
Interface 1

Languages

Go100%

Modules by API surface

collector/nginx_plus.go57 symbols
exporter.go12 symbols
client/nginx.go6 symbols
exporter_test.go4 symbols
collector/nginx.go4 symbols
collector/helper.go3 symbols
collector/helper_test.go1 symbols
client/nginx_test.go1 symbols

Dependencies from manifests, versioned

github.com/alecthomas/unitsv0.0.0-2024092700094 · 1×
github.com/beorn7/perksv1.0.1 · 1×
github.com/cespare/xxhash/v2v2.3.0 · 1×
github.com/jpillora/backoffv1.0.0 · 1×
github.com/mdlayher/socketv0.4.1 · 1×
github.com/mdlayher/vsockv1.2.1 · 1×
github.com/munnerz/goautonegv0.0.0-2019101008341 · 1×
github.com/mwitkow/go-conntrackv0.0.0-2019071606494 · 1×
github.com/nginx/nginx-plus-go-client/v3v3.0.1 · 1×
github.com/pires/go-proxyprotov0.8.1 · 1×

For agents

$ claude mcp add nginx-prometheus-exporter \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact