Metrics and health indicators
Expose only a management endpoint
The stub status module reports basic connection and request activity in Nginx Open Source when built with the module. It cannot provide per-route status classes or latency distributions. Keep the listener separate from application traffic and bound to loopback in a same-host collector setup. In containers, loopback means the same network namespace, so a separate collector may need a private management network and explicit access control. This partial http-context server is used in the lab.
server { listen 127.0.0.1:19446; location = /basic_status { allow 127.0.0.1; deny all; stub_status; } location / { return 404; }}Distinguish counters and gauges
Accepted and handled connections and total client requests are cumulative counters. Handled can fall behind accepted when resource limits interfere. Active, Reading, Writing and Waiting describe current connections; Waiting includes idle keepalive connections. They are gauges, not totals or request rates. Multiple requests can share a connection. A scrape of the status endpoint itself contributes traffic. To estimate request rate from two counter samples, divide their nonnegative difference by elapsed seconds only if the counter series is continuous; treat resets or missing samples separately.
Active connections: 4server accepts handled requests 100 99 180Reading: 1 Writing: 1 Waiting: 2# Later requests=200 after 10 seconds: 2 requests/s if no reset.Calculate a service-level indicator
A service-level indicator (SLI) is a measured property; a service-level objective (SLO) sets a target for a defined population and window. For this fictional completed-request population, a good response means status 2xx. Exclude management probes by a declared rule and separately account for missing responses and ingestion. A real user-facing availability SLI may need edge or client probes to capture requests that never reached Nginx. Do not assume every 4xx or 5xx has identical user impact.
Eligible completed requests: 10000Good: 9990Bad: 10Availability SLI: 9990 / 10000 = 99.9%SLO: 99.95%Allowed bad: 5; consumed: 10; remaining: -5Treat missing telemetry as unknown
If the collector cannot scrape or logs stop arriving, a dashboard may show gaps or an accidental zero. This is not evidence that the site is healthy. For an empty eligible window the ratio is undefined, not 100%. A negative budget signals the target was missed in the selected window; it is not a number of failures to repair retrospectively. Use a coverage alert, independent probe and known collection health alongside the user-facing SLI. The lab calculation is for a fixed complete population and does not model rolling-window policies.
def availability(good, total): if not 0 <= good <= total: raise ValueError("invalid counts") return None if total == 0 else good / total
print(availability(9990, 10000)) # 0.999print(availability(0, 0)) # NonePractice and recap
For 2000 eligible complete requests, 1994 good, SLO 99.8%, calculate SLI, allowed bad and remaining. What if telemetry is missing? Use the staged manual practice and quiz. Next: Observability integrations.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Metrics and health indicators
Expose a private stub_status endpoint, interpret counters and gauges, and calculate request-based availability and an error budget from complete observations.
Which stub_status field is a cumulative request counter?
What does Waiting describe?
Requests rises from 180 to 200 in 10 seconds with no reset. What is the rate?
With 10 bad out of 10000 requests and a 99.95% SLO, what is the remaining error budget?
No eligible observations arrive. What is the SLI?