pub struct Family<S, M, C = fn() -> M> { /* private fields */ }
Expand description

A wrapper around prometheus_client::metrics::family::Family which encodes its labels with Serialize instead of Encode.

Examples

Basic usage:

#[derive(Clone, Eq, Hash, PartialEq, Serialize)]
struct Labels {
    method: Method,
    host: String,
}

#[derive(Clone, Eq, Hash, PartialEq, Serialize)]
enum Method {
    #[serde(rename = "GET")]
    Get,
}

let family = <Family<Labels, Counter>>::default();
let mut registry = Registry::with_prefix("http");

registry.register(
    "Incoming requests",
    "Number of requests per method and per host",
    family.clone(),
);

family
    .get_or_create(&Labels {
        method: Method::Get,
        host: "unionize.org".to_string(),
    })
    .inc();

let mut serialized = String::new();

// SAFETY: We know prometheus-client only writes UTF-8 slices.
unsafe {
    encode(&mut serialized.as_mut_vec(), &registry).unwrap();
}

assert_eq!(
    serialized,
    concat!(
        "# HELP http_Incoming requests Number of requests per method and per host.\n",
        "# TYPE http_Incoming requests counter\n",
        "http_Incoming requests_total{method=\"GET\",host=\"unionize.org\"} 1\n",
        "# EOF\n",
    ),
);

Implementations

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
Returns the “default value” for a type. Read more

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.