Struct serde_prometheus_labels::Family
source · [−]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(), ®istry).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
sourceimpl<S, M, C> Family<S, M, C>where
S: Clone + Eq + Hash,
impl<S, M, C> Family<S, M, C>where
S: Clone + Eq + Hash,
pub fn new_with_constructor(constructor: C) -> Self
sourceimpl<S, M, C> Family<S, M, C>where
S: Clone + Eq + Hash,
C: MetricConstructor<M>,
impl<S, M, C> Family<S, M, C>where
S: Clone + Eq + Hash,
C: MetricConstructor<M>,
pub fn get_or_create(&self, label_set: &S) -> MappedRwLockReadGuard<'_, M>
Trait Implementations
sourceimpl<S, M, C> EncodeMetric for Family<S, M, C>where
S: Clone + Eq + Hash + Serialize,
M: EncodeMetric + TypedMetric,
C: MetricConstructor<M>,
impl<S, M, C> EncodeMetric for Family<S, M, C>where
S: Clone + Eq + Hash + Serialize,
M: EncodeMetric + TypedMetric,
C: MetricConstructor<M>,
fn encode(&self, encoder: Encoder<'_, '_>) -> Result<()>
fn metric_type(&self) -> MetricType
sourceimpl<S, M, C> TypedMetric for Family<S, M, C>where
M: TypedMetric,
impl<S, M, C> TypedMetric for Family<S, M, C>where
M: TypedMetric,
const TYPE: MetricType = <M as TypedMetric>::TYPE
Auto Trait Implementations
impl<S, M, C = fn() -> M> !RefUnwindSafe for Family<S, M, C>
impl<S, M, C> Send for Family<S, M, C>where
C: Send,
M: Send + Sync,
S: Send + Sync,
impl<S, M, C> Sync for Family<S, M, C>where
C: Sync,
M: Send + Sync,
S: Send + Sync,
impl<S, M, C> Unpin for Family<S, M, C>where
C: Unpin,
impl<S, M, C = fn() -> M> !UnwindSafe for Family<S, M, C>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more