major refactor

* uccm add parsers and metrics for gps sats, loop diag
* cleanups and improvements
* fix refclock to survive chrony restart
* cargo updates
* etc
This commit is contained in:
2025-05-03 23:06:19 -07:00
parent a828f3267c
commit d7c57cf23a
8 changed files with 1343 additions and 677 deletions

View File

@@ -2,18 +2,17 @@ use async_trait::async_trait;
use chimemon::{ChimemonSource, ChimemonSourceChannel, Config};
use chrony_candm::reply::{self, ReplyBody, SourceMode};
use chrony_candm::request::{self, RequestBody};
use chrony_candm::{blocking_query, ClientOptions};
use influxdb2::models::DataPoint;
use log::{debug, info, warn};
use log::{info, warn};
use std::net::{SocketAddr, ToSocketAddrs};
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use tokio::runtime::Handle;
use tokio::{join, time::timeout};
use tokio::join;
pub struct ChronyClient {
pub server: SocketAddr,
client_options: ClientOptions,
config: Config,
client: chrony_candm::Client,
timeout: std::time::Duration,
}
fn datapoint_from_tracking(
@@ -104,21 +103,31 @@ impl ChronyClient {
.unwrap()
.next()
.expect("Unable to parse host:port:");
let client = chrony_candm::Client::spawn(&Handle::current(), Default::default());
let timeout = Duration::from_secs(config.sources.chrony.timeout);
let client_options = ClientOptions {
n_tries: 3,
timeout: Duration::from_secs(config.sources.chrony.timeout),
};
ChronyClient {
server,
client_options,
config,
client,
timeout,
}
}
async fn query(&self, request: RequestBody) -> Result<reply::Reply, std::io::Error> {
let server = self.server.clone();
let client_options = self.client_options.clone();
tokio::task::spawn_blocking(move || blocking_query(request, client_options, &server))
.await
.map_err(|e| {
std::io::Error::new(
std::io::ErrorKind::Other,
format!("Error joining thread: {}", e),
)
})?
}
pub async fn get_tracking(&self) -> Result<reply::Tracking, std::io::Error> {
let reply = timeout(
self.timeout,
self.client.query(RequestBody::Tracking, self.server),
)
.await??;
let reply = self.query(RequestBody::Tracking).await?;
match reply.body {
ReplyBody::Tracking(tracking) => Ok(tracking),
@@ -130,11 +139,7 @@ impl ChronyClient {
}
pub async fn get_sources(&self) -> Result<Vec<reply::SourceData>, std::io::Error> {
let reply = timeout(
self.timeout,
self.client.query(RequestBody::NSources, self.server),
)
.await??;
let reply = self.query(RequestBody::NSources).await?;
let nsources = match reply.body {
ReplyBody::NSources(ns) => Ok(i32::try_from(ns.n_sources).unwrap()),
@@ -158,14 +163,9 @@ impl ChronyClient {
}
async fn get_source(&self, index: i32) -> Result<reply::SourceData, std::io::Error> {
let reply = timeout(
self.timeout,
self.client.query(
RequestBody::SourceData(request::SourceData { index: index }),
self.server,
),
)
.await??;
let reply = self
.query(RequestBody::SourceData(request::SourceData { index }))
.await?;
let sourcedata = match reply.body {
ReplyBody::SourceData(sourcedata) => Ok(sourcedata),