Skip to content

Commit

Permalink
Expose available nts cookies in prometheus.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 committed Dec 5, 2024
1 parent 359bdf8 commit 5508d95
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions ntpd/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,23 @@ macro_rules! collect_sources {
}};
}

macro_rules! collect_some_sources {
($from: expr, |$ident: ident| $value: expr $(,)?) => {{
let mut data = vec![];
for $ident in &$from.sources {
if let Some(value) = $value {
let labels = vec![
("name", $ident.name.clone()),
("address", $ident.address.clone()),
("id", format!("{}", $ident.id)),
];
data.push(Measurement { labels, value });
}
}
data
}};
}

macro_rules! collect_servers {
($from: expr, |$ident: ident| $value: expr $(,)?) => {{
let mut data = vec![];
Expand Down Expand Up @@ -232,6 +249,15 @@ pub fn format_state(w: &mut impl std::fmt::Write, state: &ObservableState) -> st
collect_sources!(state, |p| p.unanswered_polls),
)?;

format_metric(
w,
"ntp_source_nts_cookies_available",
"Number of unused cookies available for nts-enabled ntp exchanges",
MetricType::Gauge,
None,
collect_some_sources!(state, |p| p.nts_cookies),
)?;

format_metric(
w,
"ntp_source_offset",
Expand Down

0 comments on commit 5508d95

Please sign in to comment.