use mz_ore::metric;
use mz_ore::metrics::raw::IntCounterVec;
use mz_ore::metrics::{IntCounter, MetricsRegistry};
#[derive(Clone, Debug)]
pub struct MetricsConfig {
connection_status: IntCounterVec,
}
impl MetricsConfig {
pub fn register_into(registry: &MetricsRegistry) -> Self {
Self {
connection_status: registry.register(metric! {
name: "mz_connection_status",
help: "Count of completed network connections, by status",
var_labels: ["source", "status"],
}),
}
}
}
#[derive(Clone, Debug)]
pub struct Metrics {
inner: MetricsConfig,
label: &'static str,
}
impl Metrics {
pub fn new(inner: MetricsConfig, label: &'static str) -> Self {
let self_ = Self { inner, label };
self_.connection_status(false);
self_.connection_status(true);
self_
}
pub fn connection_status(&self, is_ok: bool) -> IntCounter {
self.inner
.connection_status
.with_label_values(&[self.source_label(), Self::status_label(is_ok)])
}
fn status_label(is_ok: bool) -> &'static str {
if is_ok {
"success"
} else {
"error"
}
}
fn source_label(&self) -> &'static str {
self.label
}
}