treewide: set up rustfmt and taplo with custom rules

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I794f9152bb02e3dd91c9738369b94fc66a6a6964
This commit is contained in:
raf 2026-02-19 01:42:28 +03:00
commit ffae695240
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
27 changed files with 1851 additions and 1618 deletions

View file

@ -1,5 +1,5 @@
[package]
name = "scanner-system"
name = "scanner-system"
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_system"
path = "src/lib.rs"
crate-type = ["cdylib"]
crate-type = [ "cdylib" ]
name = "scanner_system"
path = "src/lib.rs"

View file

@ -1,80 +1,94 @@
use pscand_core::helpers::{ResourceHelper, SystemHelper};
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::{
ResourceHelper,
SystemHelper,
},
scanner::{
MetricValue,
Scanner,
},
Result,
};
#[derive(Default)]
struct SystemScanner {
_prev_cpu: Option<HashMap<String, f64>>,
_prev_cpu: Option<HashMap<String, f64>>,
}
#[no_mangle]
pub extern "C" fn pscand_scanner() -> *mut std::os::raw::c_void {
Box::into_raw(Box::new(SystemScanner::default())) as *mut std::os::raw::c_void
pub extern fn pscand_scanner() -> *mut std::os::raw::c_void {
Box::into_raw(Box::new(SystemScanner::default())) as *mut std::os::raw::c_void
}
impl Scanner for SystemScanner {
fn name(&self) -> &'static str {
"system"
fn name(&self) -> &'static str {
"system"
}
fn interval(&self) -> Duration {
Duration::from_secs(1)
}
fn init(&mut self, _config: &toml::Value) -> Result<()> {
Ok(())
}
fn collect(&self) -> Result<HashMap<String, MetricValue>> {
let mut metrics = HashMap::new();
if let Ok(uptime) = SystemHelper::uptime() {
metrics.insert(
"uptime_secs".to_string(),
MetricValue::from_f64(uptime.as_secs_f64()),
);
}
fn interval(&self) -> Duration {
Duration::from_secs(1)
if let Ok((load1, load5, load15)) = SystemHelper::load_average() {
metrics.insert("load_1m".to_string(), MetricValue::from_f64(load1));
metrics.insert("load_5m".to_string(), MetricValue::from_f64(load5));
metrics.insert("load_15m".to_string(), MetricValue::from_f64(load15));
}
fn init(&mut self, _config: &toml::Value) -> Result<()> {
Ok(())
if let Ok(cpu) = ResourceHelper::cpu_usage() {
if let Some(total) = cpu.get("total_usage_percent") {
metrics
.insert("cpu_percent".to_string(), MetricValue::from_f64(*total));
}
}
fn collect(&self) -> Result<HashMap<String, MetricValue>> {
let mut metrics = HashMap::new();
if let Ok(uptime) = SystemHelper::uptime() {
metrics.insert(
"uptime_secs".to_string(),
MetricValue::from_f64(uptime.as_secs_f64()),
);
}
if let Ok((load1, load5, load15)) = SystemHelper::load_average() {
metrics.insert("load_1m".to_string(), MetricValue::from_f64(load1));
metrics.insert("load_5m".to_string(), MetricValue::from_f64(load5));
metrics.insert("load_15m".to_string(), MetricValue::from_f64(load15));
}
if let Ok(cpu) = ResourceHelper::cpu_usage() {
if let Some(total) = cpu.get("total_usage_percent") {
metrics.insert("cpu_percent".to_string(), MetricValue::from_f64(*total));
}
}
if let Ok(mem) = ResourceHelper::memory_info() {
if let Some(total) = mem.get("MemTotal") {
metrics.insert(
"mem_total_bytes".to_string(),
MetricValue::Integer(*total as i64),
);
}
if let Some(available) = mem.get("MemAvailable") {
metrics.insert(
"mem_available_bytes".to_string(),
MetricValue::Integer(*available as i64),
);
}
if let (Some(used), Some(total)) = (mem.get("MemAvailable"), mem.get("MemTotal")) {
let used_mem = total.saturating_sub(*used);
metrics.insert(
"mem_used_bytes".to_string(),
MetricValue::Integer(used_mem as i64),
);
}
}
Ok(metrics)
if let Ok(mem) = ResourceHelper::memory_info() {
if let Some(total) = mem.get("MemTotal") {
metrics.insert(
"mem_total_bytes".to_string(),
MetricValue::Integer(*total as i64),
);
}
if let Some(available) = mem.get("MemAvailable") {
metrics.insert(
"mem_available_bytes".to_string(),
MetricValue::Integer(*available as i64),
);
}
if let (Some(used), Some(total)) =
(mem.get("MemAvailable"), mem.get("MemTotal"))
{
let used_mem = total.saturating_sub(*used);
metrics.insert(
"mem_used_bytes".to_string(),
MetricValue::Integer(used_mem as i64),
);
}
}
fn cleanup(&mut self) -> Result<()> {
Ok(())
}
Ok(metrics)
}
fn cleanup(&mut self) -> Result<()> {
Ok(())
}
}