[][src]Macro metrics::histogram

macro_rules! histogram {
    #[proc_macro_hack] => { ... };
}

Records a histogram.

Histograms measure the distribution of values for a given set of measurements, and start with no initial values.

Implicit conversions

Histograms are represented as u64 values, but often come from another source, such as a time measurement. By default, histogram! will accept a u64 directly or a Duration, which uses the nanoseconds total as the converted value.

External libraries and applications can create their own conversions by implementing the IntoU64 trait for their types, which is required for the value being passed to histogram!.

Example

// A basic histogram:
histogram!("some_metric_name", 34);

// An implicit conversion from `Duration`:
let d = Duration::from_millis(17);
histogram!("some_metric_name", d);

// Specifying labels:
histogram!("some_metric_name", 38, "service" => "http");

// We can also pass labels by giving a vector or slice of key/value pairs:
let dynamic_val = "woo";
let labels = [("dynamic_key", format!("{}!", dynamic_val))];
histogram!("some_metric_name", 1337, &labels);