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
impl Stats
Sourcepub fn new(info: ServiceInfo, pool: PoolStats, server: ServerStats) -> Self
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");Sourcepub fn failure_metrics(&self) -> Arc<FailureMetrics> ⓘ
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());Sourcepub fn record_latency(&self, channel: Latency, value: u64)
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);Sourcepub fn record_payload_size(&self, value: u64)
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);Sourcepub fn record_queue_wait(&self, channel: QueueWait, value: u64)
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);Sourcepub fn record_queue_len(&self, channel: QueueGauge, value: u64)
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);Sourcepub fn pool_incr(&self, field: PoolField)
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);Sourcepub fn pool_decr(&self, field: PoolField)
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);Sourcepub fn pool_incr_by(&self, field: PoolField, delta: i64)
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.
Sourcepub fn pool_set(&self, field: PoolField, value: i64)
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);Sourcepub fn pool_get(&self, field: PoolField) -> i64
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);Sourcepub fn server_incr(&self, field: ServerField)
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);Sourcepub fn server_decr(&self, field: ServerField)
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);Sourcepub fn server_incr_by(&self, field: ServerField, delta: i64)
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.
Sourcepub fn server_set(&self, field: ServerField, value: i64)
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);Sourcepub fn server_get(&self, field: ServerField) -> i64
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);Sourcepub fn set_resource_usage(
&self,
alloc_msgs: i64,
free_msgs: i64,
alloc_mbufs: i64,
free_mbufs: i64,
dyn_memory: i64,
)
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);Sourcepub fn snapshot(&self) -> Snapshot
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");Sourcepub fn reset_histograms(&self)
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);