Logging & Monitoring
JSON access logs and their timings, stub_status metrics, probes, and alerts
Open-source Nginx exposes very few metrics. Most of what you need to know about its traffic is in the access log, so the log format matters.
A JSON access log
docker logs nginx | grep 'slow?ms=300' | tail -1
{"time": "2026-10-12T16:33:08+00:00", "request_id": "8f2112de86e994952130e2d02c48edf2",
"remote_addr": "172.30.0.1", "method": "GET", "uri": "/api/slow?ms=300", "status": 200,
"request_time": 0.305, "upstream": "172.30.0.4:8000", "upstream_status": "200",
"upstream_connect_time": "0.000", "upstream_header_time": "0.305",
"upstream_response_time": "0.305", "cache": "", "user_agent": "curl/8.7.1"}JSON means any log pipeline (Loki, Elasticsearch, a cloud logging service) can parse fields without fragile regexes. And the timings answer the first question of every latency incident: is it us or the backend?
| Pattern | Means |
|---|---|
request_time ≈ upstream_response_time | The backend is slow |
request_time ≫ upstream_response_time | The client is slow (reading or sending) |
High upstream_connect_time | Backend overloaded or unreachable |
Several addresses in upstream | Retries happened (backend failures) |
status 504, upstream_status "504, 504" | Timed out on every attempt |
The request_id is passed to the app as X-Request-ID and returned to the
client, so one id finds the request in Nginx logs, app logs and a user's
bug report.
The official image links access.log to stdout and error.log to stderr,
so docker logs shows both, and the Docker logging driver handles rotation
(max-size in compose).
stub_status and the exporter
curl -s localhost:9113/metrics | grep ^nginx_
nginx_connections_accepted 847
nginx_connections_active 1
nginx_connections_handled 847
nginx_connections_reading 0
nginx_connections_waiting 0
nginx_connections_writing 1
nginx_http_requests_total 4159
nginx_up 1That's all stub_status offers: connection counts and a request total.
No status codes, no latencies, no per-upstream data. NGINX Plus has an
API with all of that; in open source, you derive it from logs (Loki
queries, or mtail / a log exporter turning log lines into Prometheus
counters), or measure from outside with probes.
| Metric | Watch for |
|---|---|
nginx_up | 0: the exporter can't read stub_status |
rate(nginx_http_requests_total) | Traffic; a sudden drop is as alarming as a spike |
nginx_connections_waiting | Idle keepalive connections: normal, can be large |
nginx_connections_writing | Requests in progress, including waiting on backends: a rising line is a slow backend |
accepted − handled | Connections dropped at the limit (worker_connections, file descriptors) |
Probes from outside
The Prometheus stack's Blackbox exporter requests /healthz over HTTP and
/api/whoami over HTTPS, exactly as a client would, through TLS, routing
and the upstream. Its metrics include success, status code, the duration of
each phase (DNS, connect, TLS, processing) and the certificate's expiry.
The first HTTPS probe broke as soon as the catch-all server was added: it
connected as host.docker.internal, an unknown name, and was refused.
The probe module now sends SNI localhost and Host: localhost:8443.
Probes have to look like real clients, or they test the wrong thing.
Alerts
The dashboard
Grafana provisions Nginx Overview from
grafana/dashboards/Web/nginx-overview.json: status, requests per second,
active connections, HTTPS probe result and days until the certificate
expires; then requests over time, connections by state, accepted vs
handled, and probe duration by phase.
Lab
- Run
timeouts.pyand find the 7-second request in the access log. Which fields show the retry? - Run
rate_limits.pywith the dashboard open. Which panels move? - Write a LogQL or
jqquery overdocker logs nginxthat computes the share of 5xx responses per minute.