diff --git a/src/baseliner.rs b/src/baseliner.rs index 3584d57..2b19fe9 100644 --- a/src/baseliner.rs +++ b/src/baseliner.rs @@ -107,6 +107,7 @@ impl Baseliner { name: "reselection", reason: "anomaly", reflector: Some(time_data.reflector), + tags: &[], }); // If reselection is disabled this would trigger an error // so just ignore the result diff --git a/src/main.rs b/src/main.rs index cff9f88..5cab64e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -123,6 +123,7 @@ fn main() -> anyhow::Result<()> { name: "starting", reason: "", reflector: None, + tags: if config.dry_run { &[("dry_run", "true")] } else { &[] }, }); let (mut ping_listener, mut ping_sender) = match config.measurement_type { diff --git a/src/metrics.rs b/src/metrics.rs index a6cc4a6..a615e55 100644 --- a/src/metrics.rs +++ b/src/metrics.rs @@ -113,6 +113,7 @@ pub enum Metric { name: &'static str, reason: &'static str, reflector: Option, + tags: &'static [(&'static str, &'static str)], }, Dropped { count: u64, @@ -300,17 +301,23 @@ impl Metrics { name, reason, reflector, + tags, } => { - let mut tags = format!("host={host_tag},type={name}"); + let mut tag_str = format!("host={host_tag},type={name}"); if let Some(reflector) = reflector { - write!(tags, ",reflector={reflector}").unwrap_or(()); + write!(tag_str, ",reflector={reflector}").unwrap_or(()); } if !reason.is_empty() { - write!(tags, ",reason={reason}").unwrap_or(()); + write!(tag_str, ",reason={reason}").unwrap_or(()); } - writeln!(out, "sqm_event,{tags} count=1i {timestamp_ns}").unwrap_or(()); + + for (k, v) in *tags { + write!(tag_str, ",{k}={v}").unwrap_or(()); + } + + writeln!(out, "sqm_event,{tag_str} count=1i {timestamp_ns}").unwrap_or(()); } Metric::Dropped { count } => { writeln!( diff --git a/src/ratecontroller.rs b/src/ratecontroller.rs index 26547e4..16acac6 100644 --- a/src/ratecontroller.rs +++ b/src/ratecontroller.rs @@ -339,6 +339,12 @@ impl Ratecontroller { warn!( "One or both Netlink stats could not be read. Skipping rate control algorithm" ); + self.metrics.send(Metric::Event { + name: "netlink_read_failure", + reason: "", + reflector: None, + tags: &[], + }); continue; } @@ -346,6 +352,12 @@ impl Ratecontroller { if self.state_dl.deltas.is_empty() || self.state_ul.deltas.is_empty() { warn!("No reflector data available, dropping to minimum rates"); + self.metrics.send(Metric::Event { + name: "reflector_unavailable", + reason: "", + reflector: None, + tags: &[], + }); self.state_dl.next_rate = self.config.download_min_kbits; self.state_ul.next_rate = self.config.upload_min_kbits; diff --git a/src/reflector_selector.rs b/src/reflector_selector.rs index 1a24055..e2adbe8 100644 --- a/src/reflector_selector.rs +++ b/src/reflector_selector.rs @@ -43,6 +43,7 @@ impl ReflectorSelector { name: "reflector_selection", reason: if triggered { "triggered" } else { "timeout" }, reflector: None, + tags: &[], }); // After 40 reselections, slow down to every 15 minutes @@ -131,6 +132,7 @@ impl ReflectorSelector { name: "reflector_selected", reason: "", reflector: Some(peer), + tags: &[], }); }