pub struct Histogram { /* private fields */ }
Expand description

Open Metrics Histogram to measure distributions of discrete events.

let histogram = Histogram::new(exponential_buckets(1.0, 2.0, 10));
histogram.observe(4.2);

Histogram does not implement Default, given that the choice of bucket values depends on the situation Histogram is used in. As an example, to measure HTTP request latency, the values suggested in the Golang implementation might work for you:

// Default values from go client(https://github.com/prometheus/client_golang/blob/5d584e2717ef525673736d72cd1d12e304f243d7/prometheus/histogram.go#L68)
let custom_buckets = [
   0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0,
];
let histogram = Histogram::new(custom_buckets.into_iter());
histogram.observe(4.2);

Implementations§

Create a new Histogram.

Examples found in repository?
src/metrics/exemplar.rs (line 243)
239
240
241
242
243
244
245
246
    pub fn new(buckets: impl Iterator<Item = f64>) -> Self {
        Self {
            inner: Arc::new(RwLock::new(HistogramWithExemplarsInner {
                exemplars: Default::default(),
                histogram: Histogram::new(buckets),
            })),
        }
    }

Observe the given value.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Encode the given instance in the OpenMetrics text encoding.
The OpenMetrics metric type of the instance.
The OpenMetrics metric type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.