Skip to main content

Metrics

Struct Metrics 

Source
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

Source

pub fn new() -> Self

Source

pub fn record_request(&self, outcome: &str)

Count one finished request under its outcome label.

Source

pub fn observe_latency(&self, elapsed: Duration)

Observe a request’s end-to-end latency into the histogram.

Source

pub fn record_llm_latency(&self, ttft: Duration, tpot: Option<Duration>)

Observe a streamed LLM response’s server-side time-to-first-token and, when the response had more than one output token, its mean time-per-output-token. Called once per streamed LLM request from the response body’s Drop, after the terminal usage frame is parsed. The gateway sits in the token stream, so these are measured with no client clock and no in-app instrumentation — the request-path advantage a trace backend (which only sees span-end duration) can’t offer.

Source

pub fn record_ratelimit_hit(&self, scope: &str)

Count a rate-limit rejection by which limiter scope tripped (ip/route/key).

Source

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.

Source

pub fn record_csp_report(&self)

Count one received CSP violation report.

Source

pub fn add_usage_request(&self, outcome: &str)

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. outcome is the request’s outcome label; a denial outcome (see [outcome_is_blocked]) also bumps the drainable blocked accumulator, so the control plane can show what the edge screened.

Source

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.

Source

pub fn drain_usage(&self) -> DrainedUsage

Atomically read-and-zero the usage accumulators — the delta the usage reporter ships to the control plane (requests + bandwidth + LLM tokens/cost, gateway L4).

Source

pub fn restore_usage(&self, u: &DrainedUsage)

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.)

Source

pub fn record_llm_usage(&self, model: &str, s: LlmSample)

Record one metered LLM request for model: add its four token dimensions and — when the model was priced — its cost (micro-dollars). cost_micros == None means the model isn’t in the price book, so tokens are still counted but the request is bucketed unpriced rather than metered. Also updates the bounded per-model breakdown (edgeguard_llm_model_*).

Source

pub fn record_llm_team_usage(&self, team: &str, s: &LlmSample)

Record one metered LLM request against its team ([llm].team_header value; absent → _none), for per-team chargeback/showback (edgeguard_llm_team_*). Bounded exactly like the per-model breakdown. Called alongside Self::record_llm_usage from the request path.

Source

pub fn record_llm_key_usage(&self, key: &str, s: &LlmSample)

Record one metered LLM request against its authenticated key/principal (_anon when unauthenticated), for per-user cost attribution (edgeguard_llm_key_*). Bounded exactly like the per-model breakdown. Reuses the existing OSS auth principal as the identity — so per-key FinOps is reachable without the EE control plane.

Source

pub fn record_budget_blocked(&self, scope: &str)

Record a request blocked by a hard LLM budget, by the budget’s scope (unknown → other).

Source

pub fn record_budget_consumed(&self, name: &str, ratio: f64)

Record the latest consumed ratio (used / limit) for a budget by name — the near-limit gauge. Last writer wins per name (a coarse “is any budget near its cap” signal). NaN/negative samples are dropped so a divide-by-zero can’t poison the gauge.

Source

pub fn record_budget_reconcile_failures(&self, n: usize)

Record n budget reconcile/release failures against the shared store (after retries). A non-zero rate here means the distributed budget counter is drifting — the signal to alert on.

Source

pub fn record_llm_no_usage(&self)

Record an LLM request whose response carried no usage (error, or a stream the client didn’t opt into usage on). No tokens/cost, but the request is visible as no_usage.

Source

pub fn record_keyvault(&self, result: &str)

Record a key-vault decision by result (swapped/denied_key/denied_model).

Source

pub fn record_dlp_finding(&self, category: &str)

Record one DLP finding under its category (unknown → other).

Source

pub fn record_dlp_blocked(&self)

Record a request blocked by DLP block mode.

Source

pub fn render(&self) -> String

Render the Prometheus text exposition (format version 0.0.4).

Trait Implementations§

Source§

impl Default for Metrics

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more