pub struct MetricHistogram { /* private fields */ }Expand description
Fixed-bucket latency histogram.
Tracks the distribution of values (typically durations in microseconds) across predefined buckets. No allocator needed — the bucket array is inline. Uses 10 buckets: 100us, 500us, 1ms, 5ms, 10ms, 50ms, 100ms, 500ms, 1s, +Inf.
Buckets are cumulative: each bucket count includes all observations that also fall into lower buckets. This matches the Prometheus histogram convention.
§Examples
use grafos_observe::MetricHistogram;
let h = MetricHistogram::new();
h.observe(50); // 50us — lands in the <=100us bucket
h.observe(2_000); // 2ms — lands in the <=5ms bucket
assert_eq!(h.count(), 2);
assert_eq!(h.sum(), 2050);
assert_eq!(h.bucket_count(0), 1); // <=100us: only the 50us observation
assert_eq!(h.bucket_count(3), 2); // <=5ms: both observationsImplementations§
Source§impl MetricHistogram
impl MetricHistogram
Sourcepub const NUM_BUCKETS: usize = 10usize
pub const NUM_BUCKETS: usize = 10usize
Number of histogram buckets.
Sourcepub const BUCKET_BOUNDS: [u64; 10]
pub const BUCKET_BOUNDS: [u64; 10]
Bucket boundaries in microseconds.
Sourcepub fn observe(&self, value_us: u64)
pub fn observe(&self, value_us: u64)
Record an observation (value in microseconds).
Increments the count for every bucket whose bound is >= the value (cumulative histogram, matching Prometheus convention).
Sourcepub fn bucket_count(&self, index: usize) -> u64
pub fn bucket_count(&self, index: usize) -> u64
Read the cumulative count for a specific bucket index.
Sourcepub fn bucket_bound(&self, index: usize) -> u64
pub fn bucket_bound(&self, index: usize) -> u64
Read the bucket upper bound for a specific bucket index (in microseconds).