pub struct Stats { /* private fields */ }Expand description
Top-level stats aggregator. Cheap to clone (Arc inside for the shared
runtime state). One instance per relay; sessions get tier-scoped handles via
Stats::tier. Build it from a StatsConfig via Stats::new.
Implementations§
Source§impl Stats
impl Stats
Sourcepub fn new(config: StatsConfig) -> Self
pub fn new(config: StatsConfig) -> Self
Build a stats aggregator from config.
When config has an origin, this spawns the snapshot task immediately
and publishes the stats broadcast; the task runs until the last Stats
clone is dropped. With no origin the aggregator is a no-op (bumps are
dropped, nothing is published) and no task spawns, so it’s safe to build
outside an async runtime.
Sourcepub fn tier(&self, tier: Tier) -> StatsHandle
pub fn tier(&self, tier: Tier) -> StatsHandle
Returns a tier-scoped handle. Bumps through this handle land in the tier’s counters.
Sourcepub fn snapshot(&self) -> StatsSnapshot
pub fn snapshot(&self) -> StatsSnapshot
Take a host-level StatsSnapshot: every counter summed across all
tracked broadcasts, split by tier and role, plus per-tier session
presence. Briefly takes the entry then the session locks. Returns an
all-zero snapshot for a no-op aggregator (stats disabled).
Unlike the published .stats broadcast, this collapses per-broadcast
detail into node totals, which is what a /metrics-style scrape wants.