Skip to main content

Module metrics

Module metrics 

Source
Expand description

Server-wide and per-route Prometheus metrics.

Server-wide counters (REQUESTS_TOTAL, ERRORS_TOTAL, ACTIVE_CONNECTIONS) are updated by the server core automatically.

Per-route metrics are opt-in: wrap your application with MetricsLayer and each request will be attributed to its (method, path) pair, emitting:

  • rws_route_requests_total{method,path,status} — request counts
  • rws_route_duration_seconds{method,path} — latency histogram

HTTP server duration — http_server_request_duration_seconds, the OpenTelemetry http.server.request.duration metric, recorded by the server core for every request (http); native-histogram buckets are served in the protobuf format (exposition) to a scraper that asks for it.

Circuit breaker state — rws_circuit_breaker_state{backend} (gauge, 0=closed, 1=half_open, 2=open) is emitted automatically for every backend known to crate::circuit_breaker::global, with no opt-in layer needed — see crate::circuit_breaker and crate::proxy::ReverseProxy::with_circuit_breaker.

§Example

use rust_web_server::app::App;
use rust_web_server::core::New;
use rust_web_server::metrics::MetricsLayer;

let app = App::new().wrap(MetricsLayer);

Modules§

exposition
The Prometheus protobuf exposition format (io.prometheus.client.MetricFamily, length-delimited), served by GET /metrics to a scraper that asks for it. It is the only format that carries native histograms.
http
http.server.request.duration — the OpenTelemetry HTTP semantic-convention server metric, recorded by the server core for every request on every protocol (no layer needed).
llm
rws_llm_* series for the LLM proxy (18.9.0).
tls
TLS metrics: what each handshake negotiated, and when the served certificates expire.

Structs§

MetricsLayer
Middleware that records per-route request counts and latency histograms.

Statics§

ACTIVE_CONNECTIONS
Number of currently open TCP/QUIC connections.
ERRORS_TOTAL
Requests that caused an application-level error (app.execute returned Err).
REQUESTS_TOTAL
Total HTTP requests handled across all connections and protocols.
SERVER_READY
Set to true after crate::server::Server::setup completes. The /readyz controller returns 503 until this is true. Set back to false when a shutdown signal is received so that Kubernetes stops routing traffic before the pod exits.
THREAD_POOL_QUEUED
Jobs queued in the thread pool waiting for a free worker.

Functions§

connection_close
connection_open
prometheus_text
Returns a Prometheus text-format snapshot of all server-wide and per-route metrics.
record_error
record_request
record_route
Record a completed request in the per-route store.