treewide: set up rustfmt and taplo with custom rules
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I794f9152bb02e3dd91c9738369b94fc66a6a6964
This commit is contained in:
parent
a4a0b9135a
commit
ffae695240
27 changed files with 1851 additions and 1618 deletions
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "scanner-sensor"
|
||||
name = "scanner-sensor"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
|
@ -7,9 +7,9 @@ authors.workspace = true
|
|||
|
||||
[dependencies]
|
||||
pscand-core.workspace = true
|
||||
toml.workspace = true
|
||||
toml.workspace = true
|
||||
|
||||
[lib]
|
||||
name = "scanner_sensor"
|
||||
path = "src/lib.rs"
|
||||
crate-type = ["cdylib"]
|
||||
crate-type = [ "cdylib" ]
|
||||
name = "scanner_sensor"
|
||||
path = "src/lib.rs"
|
||||
|
|
|
|||
|
|
@ -1,79 +1,92 @@
|
|||
use pscand_core::helpers::SensorHelper;
|
||||
use pscand_core::scanner::{MetricValue, Scanner};
|
||||
use pscand_core::Result;
|
||||
use std::collections::HashMap;
|
||||
use std::time::Duration;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use pscand_core::{
|
||||
helpers::SensorHelper,
|
||||
scanner::{
|
||||
MetricValue,
|
||||
Scanner,
|
||||
},
|
||||
Result,
|
||||
};
|
||||
|
||||
struct SensorScanner;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn pscand_scanner() -> *mut std::os::raw::c_void {
|
||||
Box::into_raw(Box::new(SensorScanner)) as *mut std::os::raw::c_void
|
||||
pub extern fn pscand_scanner() -> *mut std::os::raw::c_void {
|
||||
Box::into_raw(Box::new(SensorScanner)) as *mut std::os::raw::c_void
|
||||
}
|
||||
|
||||
impl Default for SensorScanner {
|
||||
fn default() -> Self {
|
||||
Self
|
||||
}
|
||||
fn default() -> Self {
|
||||
Self
|
||||
}
|
||||
}
|
||||
|
||||
impl Scanner for SensorScanner {
|
||||
fn name(&self) -> &'static str {
|
||||
"sensor"
|
||||
}
|
||||
fn name(&self) -> &'static str {
|
||||
"sensor"
|
||||
}
|
||||
|
||||
fn interval(&self) -> Duration {
|
||||
Duration::from_secs(2)
|
||||
}
|
||||
fn interval(&self) -> Duration {
|
||||
Duration::from_secs(2)
|
||||
}
|
||||
|
||||
fn init(&mut self, _config: &toml::Value) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
fn init(&mut self, _config: &toml::Value) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn collect(&self) -> Result<HashMap<String, MetricValue>> {
|
||||
let mut metrics = HashMap::new();
|
||||
fn collect(&self) -> Result<HashMap<String, MetricValue>> {
|
||||
let mut metrics = HashMap::new();
|
||||
|
||||
if let Ok(sensors) = SensorHelper::all_sensors() {
|
||||
let mut temp_count = 0;
|
||||
let mut fan_count = 0;
|
||||
if let Ok(sensors) = SensorHelper::all_sensors() {
|
||||
let mut temp_count = 0;
|
||||
let mut fan_count = 0;
|
||||
|
||||
for (hwmon, values) in sensors {
|
||||
for (key, value) in values {
|
||||
if key.starts_with("temp_") && key.ends_with("_celsius") {
|
||||
if let Ok(v) = value.parse::<f64>() {
|
||||
metrics.insert(format!("{}_{}", hwmon, key), MetricValue::from_f64(v));
|
||||
temp_count += 1;
|
||||
if temp_count <= 3 {
|
||||
metrics.insert(
|
||||
format!("temp_{}", temp_count),
|
||||
MetricValue::from_f64(v),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if key.starts_with("fan_") && key.ends_with("_rpm") {
|
||||
if let Ok(v) = value.parse::<f64>() {
|
||||
metrics.insert(format!("{}_{}", hwmon, key), MetricValue::from_f64(v));
|
||||
fan_count += 1;
|
||||
if fan_count <= 2 {
|
||||
metrics
|
||||
.insert(format!("fan_{}", fan_count), MetricValue::from_f64(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
if key.starts_with("voltage_") {
|
||||
if let Ok(v) = value.parse::<f64>() {
|
||||
metrics.insert(format!("{}_{}", hwmon, key), MetricValue::from_f64(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
for (hwmon, values) in sensors {
|
||||
for (key, value) in values {
|
||||
if key.starts_with("temp_") && key.ends_with("_celsius") {
|
||||
if let Ok(v) = value.parse::<f64>() {
|
||||
metrics
|
||||
.insert(format!("{}_{}", hwmon, key), MetricValue::from_f64(v));
|
||||
temp_count += 1;
|
||||
if temp_count <= 3 {
|
||||
metrics.insert(
|
||||
format!("temp_{}", temp_count),
|
||||
MetricValue::from_f64(v),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if key.starts_with("fan_") && key.ends_with("_rpm") {
|
||||
if let Ok(v) = value.parse::<f64>() {
|
||||
metrics
|
||||
.insert(format!("{}_{}", hwmon, key), MetricValue::from_f64(v));
|
||||
fan_count += 1;
|
||||
if fan_count <= 2 {
|
||||
metrics.insert(
|
||||
format!("fan_{}", fan_count),
|
||||
MetricValue::from_f64(v),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
if key.starts_with("voltage_") {
|
||||
if let Ok(v) = value.parse::<f64>() {
|
||||
metrics
|
||||
.insert(format!("{}_{}", hwmon, key), MetricValue::from_f64(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(metrics)
|
||||
}
|
||||
}
|
||||
|
||||
fn cleanup(&mut self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
Ok(metrics)
|
||||
}
|
||||
|
||||
fn cleanup(&mut self) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue