MetricsRegistry
struct MetricsRegistryCounter / gauge / histogram aggregate.
The registry is the storage backing one Metrics[Inner]
middleware. It is per-worker (see module docstring "Concurrency
note" for why); aggregation across workers is the caller's
job at the /metrics scrape endpoint.
All counters are plain UInt64. Wrap-around is bounded by
2^64 requests (~580 years at 1 G req/s).
Implements Copyable, Defaultable, Movable
- Fields
requests_total: List[UInt64]: Flat[method × status]table; index =method_idx * _STATUS_COUNT + status_idx.duration_buckets: List[UInt64]: Histogram bucket counts; flat over the 13-bucket layout. Each bucket holds the CUMULATIVE count of requests with latency<= le[i](Prometheus convention).duration_sum_micros: UInt64: Cumulative latency in microseconds. Renders as seconds in the exposition output.duration_count: UInt64: Cumulative request count for the histogram (= the value of the+Infbucket).in_flight: UInt64: Gauge of currently-serving requests. Bumped on entry, decremented on exit;Metrics.servedecrements via theexceptpath so a raisedExceptionstill drops the gauge.errors_total: UInt64: Counter of errors raised by the inner handler.
__init__
def __init__(out self) record
def record(mut self, method_idx: Int, status_idx: Int, latency_micros: UInt64) Record a successful request-served event.
record_error
def record_error(mut self, latency_micros: UInt64) Record an error from the inner handler. The error is also bucketed into the latency histogram so a slow-then- raise handler shows up in the latency graph too.
enter
def enter(mut self) Bump the in-flight gauge on request entry.
exit
def exit(mut self) Drop the in-flight gauge on request completion (success or error).
render
def render(self) -> String Snapshot the registry as a Prometheus text-format exposition body.