fix chrony refids

This commit is contained in:
2026-09-23 23:47:29 -07:00
parent c22ad764e6
commit b3481686b2
3 changed files with 570 additions and 604 deletions
+23 -1
View File
@@ -2,6 +2,7 @@ use std::net::{SocketAddr, ToSocketAddrs};
use std::sync::Arc;
use async_trait::async_trait;
use chrony_candm::common::ChronyAddr;
use chrony_candm::reply::{self, ReplyBody, SourceMode};
use chrony_candm::request::{self, RequestBody};
use chrony_candm::{ClientOptions, blocking_query};
@@ -40,6 +41,23 @@ pub struct ChronyTrackingReport {
pub last_update_interval: f64,
}
pub fn addr_to_string(addr: &ChronyAddr) -> String {
match addr {
ChronyAddr::V4(a) => a
.octets()
.iter()
.map_while(|c| {
if *c == 0 {
None
} else {
Some(char::from_u32(*c as u32).unwrap())
}
})
.collect(),
_ => addr.to_string(),
}
}
impl SourceReportDetails for ChronyTrackingReport {
fn is_healthy(&self) -> bool {
true
@@ -79,8 +97,12 @@ impl SourceReportDetails for ChronySourcesReport {
let mut metrics = Vec::with_capacity(self.sources.len());
for source in &self.sources {
let ref_id = match source.stratum {
0 => addr_to_string(&source.ip_addr),
_ => source.ip_addr.to_string(),
};
let tags = Arc::new(vec![
("ref_id", source.ip_addr.to_string()),
("ref_id", ref_id),
(
"mode",
match source.mode {