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

§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);

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.