CacheMetrics

Struct CacheMetrics 

Source
pub struct CacheMetrics {
    pub prefill_latency: MetricHistogram,
    pub first_token_latency: MetricHistogram,
    pub decode_latency: MetricHistogram,
    pub hit_total: MetricCounter,
    pub miss_total: MetricCounter,
    pub resident_bytes: MetricGauge,
    pub spill_bytes_total: MetricCounter,
    pub warmup_bytes_total: MetricCounter,
    pub attach_failure_total: MetricCounter,
    pub fork_total: MetricCounter,
    pub reclaim_total: MetricCounter,
    pub decode_far_from_cache: MetricCounter,
}
Expand description

Aggregated cache observability metrics.

Provides counters, gauges, and histograms for the 12 cache metrics defined in the design document Section 7.5. Access the process-wide singleton via CacheMetrics::global().

For labeled metrics (e.g. hit_total by cache_class, resident_bytes by tier), per-label tracking is left to the caller — the counters here provide the aggregate emission point. Callers should use the metric name constants along with labels when exporting to Prometheus or OTLP.

Fields§

§prefill_latency: MetricHistogram

Histogram: prefill latency in microseconds.

§first_token_latency: MetricHistogram

Histogram: time to first token in microseconds.

§decode_latency: MetricHistogram

Histogram: steady-state per-token decode latency in microseconds.

§hit_total: MetricCounter

Counter: total cache hits (across all cache classes).

§miss_total: MetricCounter

Counter: total cache misses (across all cache classes).

§resident_bytes: MetricGauge

Gauge: total resident bytes (across all tiers).

§spill_bytes_total: MetricCounter

Counter: total bytes spilled between tiers.

§warmup_bytes_total: MetricCounter

Counter: total bytes warmed between tiers.

§attach_failure_total: MetricCounter

Counter: total attach failures.

§fork_total: MetricCounter

Counter: total cache forks.

§reclaim_total: MetricCounter

Counter: total cache reclaims (expired + revoked + evicted).

§decode_far_from_cache: MetricCounter

Counter: decode requests placed far from cache.

Implementations§

Source§

impl CacheMetrics

Source

pub const fn new() -> Self

Create a new metrics instance with all values at zero.

Source

pub fn global() -> &'static CacheMetrics

Access the global cache metrics instance.

Source

pub fn record_cache_created(&self, logical_bytes: u64)

Record a cache creation: increments resident_bytes by the given amount.

Source

pub fn record_cache_hit(&self)

Record a cache hit for the given cache class.

Source

pub fn record_cache_miss(&self)

Record a cache miss for the given cache class.

Source

pub fn record_attach_failure(&self)

Record a cache attach failure.

Source

pub fn record_cache_spill(&self, bytes_moved: u64)

Record a cache spill: increments spill_bytes_total.

Source

pub fn record_cache_warmup(&self, bytes_moved: u64)

Record a cache warmup: increments warmup_bytes_total.

Source

pub fn record_cache_reclaimed(&self, logical_bytes: u64)

Record a cache destruction/eviction: decrements resident_bytes and increments reclaim_total.

Source

pub fn record_cache_forked(&self, logical_bytes: u64)

Record a cache fork: increments fork_total and resident_bytes.

Source

pub fn record_prefill_latency(&self, latency_us: u64)

Record a prefill latency observation.

Source

pub fn record_first_token_latency(&self, latency_us: u64)

Record a first-token latency observation.

Source

pub fn record_decode_latency(&self, latency_us: u64)

Record a decode latency observation.

Source

pub fn record_decode_far_from_cache(&self)

Record a decode request placed far from cache.

Trait Implementations§

Source§

impl Default for CacheMetrics

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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