Trait hotshot_types::traits::metrics::MetricsFamily

source ·
pub trait MetricsFamily<M>:
    Send
    + Sync
    + DynClone
    + Debug {
    // Required method
    fn create(&self, labels: Vec<String>) -> M;
}
Expand description

A family of related metrics, partitioned by their label values.

All metrics in a family have the same name. They are distinguished by a vector of strings called labels. Each label has a name and a value, and each distinct vector of label values within a family acts like a distinct metric.

The family object is used to instantiate individual metrics within the family via the create method.

§Examples

§Counting HTTP requests, partitioned by method.

let metrics: Box<dyn Metrics>;
let http_count = metrics.counter_family("http".into(), vec!["method".into()]);
let get_count = http_count.create(vec!["GET".into()]);
let post_count = http_count.create(vec!["POST".into()]);

get_count.add(1);
post_count.add(2);

This creates Prometheus metrics like

http{method="GET"} 1
http{method="POST"} 2

§Using labels to store key-value text pairs.

let metrics: Box<dyn Metrics>;
metrics
    .text_family("version".into(), vec!["semver".into(), "rev".into()])
    .create(vec!["0.1.0".into(), "891c5baa5".into()]);

This creates Prometheus metrics like

version{semver="0.1.0", rev="891c5baa5"} 1

Required Methods§

source

fn create(&self, labels: Vec<String>) -> M

Instantiate a metric in this family with a specific label vector.

The given values of labels are used to identify this metric within its family. It must contain exactly one value for each label name defined when the family was created, in the same order.

Implementors§