1use mz_ore::metric;
11use mz_ore::metrics::raw::IntCounterVec;
12use mz_ore::metrics::{IntCounter, MetricsRegistry};
13
14#[derive(Clone, Debug)]
15pub struct MetricsConfig {
16 connection_status: IntCounterVec,
17}
18
19impl MetricsConfig {
20 pub fn register_into(registry: &MetricsRegistry) -> Self {
21 Self {
22 connection_status: registry.register(metric! {
23 name: "mz_connection_status",
24 help: "Count of completed network connections, by status",
25 var_labels: ["source", "status"],
26 }),
27 }
28 }
29}
30
31#[derive(Clone, Debug)]
32pub struct Metrics {
33 inner: MetricsConfig,
34 label: &'static str,
35}
36
37impl Metrics {
38 pub fn new(inner: MetricsConfig, label: &'static str) -> Self {
39 let self_ = Self { inner, label };
40
41 self_.connection_status(false);
44 self_.connection_status(true);
45
46 self_
47 }
48
49 pub fn connection_status(&self, is_ok: bool) -> IntCounter {
50 self.inner
51 .connection_status
52 .with_label_values(&[self.source_label(), Self::status_label(is_ok)])
53 }
54
55 fn status_label(is_ok: bool) -> &'static str {
56 if is_ok { "success" } else { "error" }
57 }
58
59 fn source_label(&self) -> &'static str {
60 self.label
61 }
62}