pub struct Distribution { /* private fields */ }Expand description
A container for approximating the distribution of a streaming data source.
Distributions aggregate statistics from raw samples that pass through them. They include:
total: The total number of observed values.sum: The sum of all observed values.min: The smallest observed value.max: The largest observed value.buckets: An exponential histogram backed by aBucketSet.
Call the Distribution::observe method on each raw value.
Use the Props implementation on Distribution to include it on a metric sample.
Implementations§
Source§impl Distribution
impl Distribution
Sourcepub const DEFAULT_MAX_SCALE: i32 = 20
pub const DEFAULT_MAX_SCALE: i32 = 20
The default initial scale used when converting observed values into bucket midpoints.
Sourcepub const DEFAULT_MAX_BUCKETS: usize = 160
pub const DEFAULT_MAX_BUCKETS: usize = 160
The default maximum number of buckets before rescaling will apply.
Sourcepub fn new(max_scale: i32, max_buckets: usize) -> Self
pub fn new(max_scale: i32, max_buckets: usize) -> Self
Create a new Distribution that can store up to max_buckets sparse buckets, at up to max_scale precision.
The distribution uses a large scale initially. Whenever the number of buckets would overflow max_buckets, the scale is decremented and the buckets are rescaled. This reduces the number of buckets by half while also decreasing precision.
Sourcepub fn observe(&mut self, raw_value: f64)
pub fn observe(&mut self, raw_value: f64)
Observe a raw value.
The value will be converted into a bucket midpoint at the current internal scale. The count for the resulting bucket will be incremented by 1.
§Panics
This method will panic if adding count to an existing entry in value would overflow.
Sourcepub fn observe_all(&mut self, raw_value: f64, count: u64)
pub fn observe_all(&mut self, raw_value: f64, count: u64)
Observe a raw value.
The value will be converted into a bucket midpoint at the current internal scale. The count for the resulting bucket will be incremented by 1.
§Panics
This method will panic if adding count to an existing entry in value would overflow.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Clear the distribution of any data so it can be re-used.
This method will also reset the internal scale back to its initial value.
Sourcepub fn count(&self) -> u64
pub fn count(&self) -> u64
Get the total count of observed values across all buckets.
This method returns 0 if no values have been seen.
Sourcepub fn min(&self) -> Option<f64>
pub fn min(&self) -> Option<f64>
Get the minimum observed value.
This method returns None if no values have been seen.
Sourcepub fn max(&self) -> Option<f64>
pub fn max(&self) -> Option<f64>
Get the maximum observed value.
This method returns None if no values have been seen.
Sourcepub fn sum(&self) -> Option<f64>
pub fn sum(&self) -> Option<f64>
Get the sum of all observed values.
This method returns None if no values have been seen.
Sourcepub fn max_buckets(&self) -> usize
pub fn max_buckets(&self) -> usize
Get the maximum number of buckets the distribution can hold before rescaling.
Trait Implementations§
Source§impl Default for Distribution
impl Default for Distribution
Source§impl Props for Distribution
impl Props for Distribution
Source§fn for_each<'kv, F: FnMut(Str<'kv>, Value<'kv>) -> ControlFlow<()>>(
&'kv self,
for_each: F,
) -> ControlFlow<()>
fn for_each<'kv, F: FnMut(Str<'kv>, Value<'kv>) -> ControlFlow<()>>( &'kv self, for_each: F, ) -> ControlFlow<()>
Source§fn get<'v, K>(&'v self, key: K) -> Option<Value<'v>>where
K: ToStr,
fn get<'v, K>(&'v self, key: K) -> Option<Value<'v>>where
K: ToStr,
Source§fn pull<'kv, V, K>(&'kv self, key: K) -> Option<V>
fn pull<'kv, V, K>(&'kv self, key: K) -> Option<V>
V. Read more