Add chrony SOCK refclock and initial UCCM source
This commit is contained in:
52
src/hwmon.rs
52
src/hwmon.rs
@@ -4,7 +4,7 @@ use futures::{stream, StreamExt};
|
||||
use influxdb2::models::DataPoint;
|
||||
use log::{debug, info};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
path::PathBuf,
|
||||
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
@@ -47,37 +47,35 @@ impl HwmonSource {
|
||||
|
||||
#[async_trait]
|
||||
impl ChimemonSource for HwmonSource {
|
||||
async fn run(self, chan: tokio::sync::broadcast::Sender<DataPoint>) {
|
||||
async fn run(self, chan: ChimemonSourceChannel) {
|
||||
info!("hwmon task started");
|
||||
let mut interval =
|
||||
tokio::time::interval(Duration::from_secs(self.config.sources.hwmon.interval));
|
||||
loop {
|
||||
interval.tick().await;
|
||||
stream::iter(&self.sensors)
|
||||
.for_each_concurrent(None, |s| async {
|
||||
let sensor_val = HwmonSource::get_raw_value(s)
|
||||
.await
|
||||
.expect("Unable to read sensor");
|
||||
debug!(
|
||||
"hwmon {} raw value {}",
|
||||
s.path.to_string_lossy(),
|
||||
sensor_val
|
||||
);
|
||||
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
||||
let mut builder =
|
||||
DataPoint::builder(&s.device).timestamp(now.as_nanos().try_into().unwrap());
|
||||
for (key, value) in &self.config.influxdb.tags {
|
||||
builder = builder.tag(key, value)
|
||||
}
|
||||
builder = builder
|
||||
.tag("sensor", &s.name)
|
||||
.field("value", sensor_val.trim().parse::<i64>().unwrap());
|
||||
let dp = builder.build().unwrap();
|
||||
|
||||
info!("Writing hwmon data: {:?}", dp);
|
||||
chan.send(dp).unwrap();
|
||||
})
|
||||
.await;
|
||||
let s = stream::iter(&self.sensors).then(|s| async {
|
||||
let sensor_val = HwmonSource::get_raw_value(s)
|
||||
.await
|
||||
.expect("Unable to read sensor");
|
||||
debug!(
|
||||
"hwmon {} raw value {}",
|
||||
s.path.to_string_lossy(),
|
||||
sensor_val
|
||||
);
|
||||
let now = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
|
||||
let mut builder =
|
||||
DataPoint::builder(&s.device).timestamp(now.as_nanos().try_into().unwrap());
|
||||
for (key, value) in &self.config.influxdb.tags {
|
||||
builder = builder.tag(key, value)
|
||||
}
|
||||
builder = builder
|
||||
.tag("sensor", &s.name)
|
||||
.field("value", sensor_val.trim().parse::<i64>().unwrap());
|
||||
builder.build().unwrap()
|
||||
});
|
||||
info!("Writing hwmon data");
|
||||
chan.send(s.collect::<Vec<DataPoint>>().await.into())
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user