pub struct Metrics { /* private fields */ }Expand description
Process-wide metric registry. All methods take &self and use relaxed atomics — metrics
are monotonic counters/observations where exact inter-thread ordering doesn’t matter.
Implementations§
Source§impl Metrics
impl Metrics
pub fn new() -> Self
Sourcepub fn record_request(&self, outcome: &str)
pub fn record_request(&self, outcome: &str)
Count one finished request under its outcome label.
Sourcepub fn observe_latency(&self, elapsed: Duration)
pub fn observe_latency(&self, elapsed: Duration)
Observe a request’s end-to-end latency into the histogram.
Sourcepub fn record_ratelimit_hit(&self, scope: &str)
pub fn record_ratelimit_hit(&self, scope: &str)
Count a rate-limit rejection by which limiter scope tripped (ip/route/key).
Sourcepub fn record_waf_hit(&self, class: &str)
pub fn record_waf_hit(&self, class: &str)
Count one WAF rule match by rule class (sqli/xss/path_traversal/custom).
Recorded for both report-only and blocking modes — so a report-first rollout is
visible — while a blocked request is additionally counted under the forbidden
request outcome.
Sourcepub fn record_csp_report(&self)
pub fn record_csp_report(&self)
Count one received CSP violation report.
Sourcepub fn add_usage_request(&self)
pub fn add_usage_request(&self)
Count one request toward the drainable usage accumulator (managed mode). Called once per
request from the single finish exit, so every request — proxied or rejected — counts.
Sourcepub fn add_usage_bytes(&self, ingress: usize, egress: usize)
pub fn add_usage_bytes(&self, ingress: usize, egress: usize)
Add request (ingress) + response (egress) bytes to the drainable usage accumulator. Called on the proxied path where both bodies are buffered and the counts are known.
Sourcepub fn drain_usage(&self) -> (u64, u64, u64)
pub fn drain_usage(&self) -> (u64, u64, u64)
Atomically read-and-zero the usage accumulators, returning (requests, ingress, egress)
accrued since the last drain — the delta the usage reporter ships to the control plane.
Sourcepub fn restore_usage(&self, requests: u64, ingress: u64, egress: u64)
pub fn restore_usage(&self, requests: u64, ingress: u64, egress: u64)
Add a previously-drained delta back, e.g. when a usage report failed to send — so the next period reships it instead of losing billable usage. (New requests that arrived during the failed send simply add on top, as intended.)