Change data structure for hwmon
This commit is contained in:
42
src/hwmon.rs
42
src/hwmon.rs
@@ -2,7 +2,7 @@ use async_trait::async_trait;
|
||||
use chimemon::{ChimemonSource, ChimemonSourceChannel, Config};
|
||||
use futures::{stream, StreamExt};
|
||||
use influxdb2::models::DataPoint;
|
||||
use log::{info, debug};
|
||||
use log::{debug, info};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||
@@ -53,23 +53,31 @@ impl ChimemonSource for HwmonSource {
|
||||
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.field(&s.name, sensor_val.trim().parse::<f64>().unwrap());
|
||||
let dp = builder.build().unwrap();
|
||||
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;
|
||||
info!("Writing hwmon data: {:?}", dp);
|
||||
chan.send(dp).unwrap();
|
||||
})
|
||||
.await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user