Skip to main content

Stats

Struct Stats 

Source
pub struct Stats { /* private fields */ }
Expand description

Live, mutable counters and histograms for a single engine instance.

Stats is the writer side; readers consume frozen Snapshot values produced by Stats::snapshot.

§Examples

use dynomite::stats::{PoolStats, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("dyn_o_mite"),
    ServerStats::new("redis"),
);
assert_eq!(stats.snapshot().pool.name, "dyn_o_mite");

Implementations§

Source§

impl Stats

Source

pub fn new(info: ServiceInfo, pool: PoolStats, server: ServerStats) -> Self

Construct a new Stats with empty counters and histograms.

§Examples
use dynomite::stats::{PoolStats, ServerStats, ServiceInfo, Stats};

let info = ServiceInfo {
    source: "node-a".into(),
    version: "0.0.1".into(),
    rack: "r1".into(),
    dc: "dc1".into(),
};
let stats = Stats::new(
    info,
    PoolStats::new("dyn_o_mite"),
    ServerStats::new("redis_local"),
);
let snap = stats.snapshot();
assert_eq!(snap.pool.name, "dyn_o_mite");
Source

pub fn failure_metrics(&self) -> Arc<FailureMetrics>

Borrow the failure-cause metrics handle.

The dispatcher and the gossip handler clone this Arc so they can record per-cause errors and per-peer state transitions. The handle is created at construction time and lives for the lifetime of the Stats value.

§Examples
use dynomite::stats::{PoolStats, ServerStats, ServiceInfo, Stats};
let s = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
let m = s.failure_metrics();
assert!(m.snapshot().is_empty());
Source

pub fn record_latency(&self, channel: Latency, value: u64)

Record a latency observation in the matching histogram.

§Examples
use dynomite::stats::{Latency, PoolStats, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.record_latency(Latency::Request, 100);
Source

pub fn record_payload_size(&self, value: u64)

Record a payload-size observation.

§Examples
use dynomite::stats::{PoolStats, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.record_payload_size(2048);
Source

pub fn record_queue_wait(&self, channel: QueueWait, value: u64)

Record a queue wait time observation.

§Examples
use dynomite::stats::{PoolStats, QueueWait, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.record_queue_wait(QueueWait::Server, 12);
Source

pub fn record_queue_len(&self, channel: QueueGauge, value: u64)

Record a queue-length sample.

§Examples
use dynomite::stats::{PoolStats, QueueGauge, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.record_queue_len(QueueGauge::ClientOut, 4);
Source

pub fn pool_incr(&self, field: PoolField)

Increment a pool counter or gauge by one.

§Examples
use dynomite::stats::{PoolField, PoolStats, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.pool_incr(PoolField::ClientEof);
assert_eq!(stats.pool_get(PoolField::ClientEof), 1);
Source

pub fn pool_decr(&self, field: PoolField)

Decrement a pool gauge by one.

§Examples
use dynomite::stats::{PoolField, PoolStats, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.pool_set(PoolField::ClientConnections, 5);
stats.pool_decr(PoolField::ClientConnections);
assert_eq!(stats.pool_get(PoolField::ClientConnections), 4);
Source

pub fn pool_incr_by(&self, field: PoolField, delta: i64)

Add delta to a pool counter or gauge.

Wraps on overflow to mirror the reference engine’s ++ / += semantics. Counters are 64-bit signed and never reach the wrap boundary under realistic workloads.

Source

pub fn pool_set(&self, field: PoolField, value: i64)

Set a pool gauge or timestamp to an absolute value.

§Examples
use dynomite::stats::{PoolField, PoolStats, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.pool_set(PoolField::PeerEjectedAt, 1_700_000_000);
assert_eq!(stats.pool_get(PoolField::PeerEjectedAt), 1_700_000_000);
Source

pub fn pool_get(&self, field: PoolField) -> i64

Read the current value of a pool metric.

§Examples
use dynomite::stats::{PoolField, PoolStats, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
assert_eq!(stats.pool_get(PoolField::ClientEof), 0);
Source

pub fn server_incr(&self, field: ServerField)

Increment a server counter or gauge by one.

§Examples
use dynomite::stats::{PoolStats, ServerField, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.server_incr(ServerField::ReadRequests);
assert_eq!(stats.server_get(ServerField::ReadRequests), 1);
Source

pub fn server_decr(&self, field: ServerField)

Decrement a server gauge by one.

§Examples
use dynomite::stats::{PoolStats, ServerField, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.server_set(ServerField::InQueue, 3);
stats.server_decr(ServerField::InQueue);
assert_eq!(stats.server_get(ServerField::InQueue), 2);
Source

pub fn server_incr_by(&self, field: ServerField, delta: i64)

Add delta to a server counter or gauge.

Wraps on overflow to mirror the reference engine’s ++ / += semantics. Counters are 64-bit signed and never reach the wrap boundary under realistic workloads.

Source

pub fn server_set(&self, field: ServerField, value: i64)

Set a server gauge or timestamp to an absolute value.

§Examples
use dynomite::stats::{PoolStats, ServerField, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.server_set(ServerField::ServerEjectedAt, 1_700_000_000);
assert_eq!(stats.server_get(ServerField::ServerEjectedAt), 1_700_000_000);
Source

pub fn server_get(&self, field: ServerField) -> i64

Read the current value of a server metric.

§Examples
use dynomite::stats::{PoolStats, ServerField, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
assert_eq!(stats.server_get(ServerField::ReadRequests), 0);
Source

pub fn set_resource_usage( &self, alloc_msgs: i64, free_msgs: i64, alloc_mbufs: i64, free_mbufs: i64, dyn_memory: i64, )

Set the resource usage gauges that the reference engine samples once per aggregation cycle.

§Examples
use dynomite::stats::{PoolStats, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.set_resource_usage(0, 0, 0, 0, 0);
assert_eq!(stats.snapshot().alloc_msgs, 0);
Source

pub fn snapshot(&self) -> Snapshot

Build an immutable snapshot of every counter, gauge, and histogram quantile at the current instant.

§Examples
use dynomite::stats::{PoolStats, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
let snap = stats.snapshot();
assert_eq!(snap.pool.name, "p");
Source

pub fn reset_histograms(&self)

Reset every histogram. The reference engine does this every five minutes from inside the aggregation loop.

§Examples
use dynomite::stats::{Latency, PoolStats, ServerStats, ServiceInfo, Stats};
let stats = Stats::new(
    ServiceInfo::default(),
    PoolStats::new("p"),
    ServerStats::new("s"),
);
stats.record_latency(Latency::Request, 50);
stats.reset_histograms();
assert_eq!(stats.snapshot().latency.max, 0);

Trait Implementations§

Source§

impl Debug for Stats

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Stats

§

impl !RefUnwindSafe for Stats

§

impl Send for Stats

§

impl Sync for Stats

§

impl Unpin for Stats

§

impl UnsafeUnpin for Stats

§

impl !UnwindSafe for Stats

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

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> 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
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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,