pub struct DynamicCounter { /* private fields */ }Expand description
Counter keyed by runtime label sets.
Uses a sharded index for key->series lookup and per-series sharded atomics for fast updates.
Implementations§
Source§impl DynamicCounter
impl DynamicCounter
Sourcepub fn with_max_series(shard_count: usize, max_series: usize) -> Self
pub fn with_max_series(shard_count: usize, max_series: usize) -> Self
Creates a new runtime-labeled counter with a series cardinality cap.
When the number of unique label sets approximately reaches max_series,
new label sets are redirected into a single overflow series
(__ft_overflow=true). The cap is checked via a lock-free atomic counter,
so concurrent inserts may briefly overshoot by the number of in-flight
writers before the overflow kicks in.
Sourcepub fn series(&self, labels: &[(&str, &str)]) -> DynamicCounterSeries
pub fn series(&self, labels: &[(&str, &str)]) -> DynamicCounterSeries
Resolve a reusable series handle for labels.
Preferred for hot paths when labels come from a finite active set.
Sourcepub fn add(&self, labels: &[(&str, &str)], value: isize)
pub fn add(&self, labels: &[(&str, &str)], value: isize)
Adds value to the series identified by labels.
Sourcepub fn get(&self, labels: &[(&str, &str)]) -> isize
pub fn get(&self, labels: &[(&str, &str)]) -> isize
Gets the current value for the series identified by labels.
Sourcepub fn snapshot(&self) -> Vec<(DynamicLabelSet, isize)>
pub fn snapshot(&self) -> Vec<(DynamicLabelSet, isize)>
Returns a snapshot of all label-set/count pairs.
Sourcepub fn cardinality(&self) -> usize
pub fn cardinality(&self) -> usize
Returns the current number of distinct label sets.
Sourcepub fn overflow_count(&self) -> u64
pub fn overflow_count(&self) -> u64
Returns the number of records routed to the overflow bucket.
A non-zero value indicates the cardinality cap was hit and label fidelity is being lost. Use this to alert on cardinality pressure.
Sourcepub fn evict_stale(&self, max_staleness: u32) -> usize
pub fn evict_stale(&self, max_staleness: u32) -> usize
Evict series that haven’t been accessed for max_staleness cycles.
Call this after advance_cycle() in your exporter task.
Series are marked as evicted (so cached handles see the tombstone),
then removed from the index.
Protected series (Arc::strong_count > 1) are never evicted - someone holds a DynamicCounterSeries handle to them.
Returns the number of series evicted.
Trait Implementations§
Source§impl ClickHouseExport for DynamicCounter
impl ClickHouseExport for DynamicCounter
fn export_clickhouse( &self, batch: &mut ClickHouseMetricBatch, name: &str, description: &str, time_unix_nano: u64, )
Source§impl DogStatsDExport for DynamicCounter
impl DogStatsDExport for DynamicCounter
Source§impl OtlpExport for DynamicCounter
impl OtlpExport for DynamicCounter
Source§impl PrometheusExport for DynamicCounter
impl PrometheusExport for DynamicCounter
Auto Trait Implementations§
impl !Freeze for DynamicCounter
impl !RefUnwindSafe for DynamicCounter
impl Send for DynamicCounter
impl Sync for DynamicCounter
impl Unpin for DynamicCounter
impl UnsafeUnpin for DynamicCounter
impl UnwindSafe for DynamicCounter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request