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-proc"
name = "scanner-proc"
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_proc"
path = "src/lib.rs"
crate-type = ["cdylib"]
crate-type = [ "cdylib" ]
name = "scanner_proc"
path = "src/lib.rs"

View file

@ -1,99 +1,107 @@
use pscand_core::helpers::ProcessHelper;
use pscand_core::scanner::{MetricValue, Scanner};
use std::collections::HashMap;
use std::time::Duration;
use std::{
collections::HashMap,
time::Duration,
};
use pscand_core::{
helpers::ProcessHelper,
scanner::{
MetricValue,
Scanner,
},
};
struct ProcScanner;
#[no_mangle]
pub extern "C" fn pscand_scanner() -> *mut std::os::raw::c_void {
Box::into_raw(Box::new(ProcScanner)) as *mut std::os::raw::c_void
pub extern fn pscand_scanner() -> *mut std::os::raw::c_void {
Box::into_raw(Box::new(ProcScanner)) as *mut std::os::raw::c_void
}
impl Default for ProcScanner {
fn default() -> Self {
Self
}
fn default() -> Self {
Self
}
}
impl Scanner for ProcScanner {
fn name(&self) -> &'static str {
"proc"
fn name(&self) -> &'static str {
"proc"
}
fn interval(&self) -> Duration {
Duration::from_secs(5)
}
fn init(&mut self, _config: &toml::Value) -> pscand_core::Result<()> {
Ok(())
}
fn collect(&self) -> pscand_core::Result<HashMap<String, MetricValue>> {
let mut metrics = HashMap::new();
if let Ok(counts) = ProcessHelper::process_count() {
if let Some(total) = counts.get("total") {
metrics.insert(
"process_total".to_string(),
MetricValue::Integer(*total as i64),
);
}
if let Some(running) = counts.get("running") {
metrics.insert(
"process_running".to_string(),
MetricValue::Integer(*running as i64),
);
}
if let Some(sleeping) = counts.get("sleeping") {
metrics.insert(
"process_sleeping".to_string(),
MetricValue::Integer(*sleeping as i64),
);
}
if let Some(zombie) = counts.get("zombie") {
metrics.insert(
"process_zombie".to_string(),
MetricValue::Integer(*zombie as i64),
);
}
}
fn interval(&self) -> Duration {
Duration::from_secs(5)
}
if let Ok(zombies) = ProcessHelper::zombie_processes() {
metrics.insert(
"zombie_count".to_string(),
MetricValue::Integer(zombies.len() as i64),
);
fn init(&mut self, _config: &toml::Value) -> pscand_core::Result<()> {
Ok(())
}
fn collect(&self) -> pscand_core::Result<HashMap<String, MetricValue>> {
let mut metrics = HashMap::new();
if let Ok(counts) = ProcessHelper::process_count() {
if let Some(total) = counts.get("total") {
metrics.insert(
"process_total".to_string(),
MetricValue::Integer(*total as i64),
);
}
if let Some(running) = counts.get("running") {
metrics.insert(
"process_running".to_string(),
MetricValue::Integer(*running as i64),
);
}
if let Some(sleeping) = counts.get("sleeping") {
metrics.insert(
"process_sleeping".to_string(),
MetricValue::Integer(*sleeping as i64),
);
}
if let Some(zombie) = counts.get("zombie") {
metrics.insert(
"process_zombie".to_string(),
MetricValue::Integer(*zombie as i64),
);
}
if !zombies.is_empty() {
let mut zombie_info = Vec::new();
for z in zombies.iter().take(5) {
zombie_info.push(format!("{}({})", z.name, z.pid));
}
if let Ok(zombies) = ProcessHelper::zombie_processes() {
metrics.insert(
"zombie_count".to_string(),
MetricValue::Integer(zombies.len() as i64),
);
if !zombies.is_empty() {
let mut zombie_info = Vec::new();
for z in zombies.iter().take(5) {
zombie_info.push(format!("{}({})", z.name, z.pid));
}
metrics.insert(
"zombie_processes".to_string(),
MetricValue::from_string(zombie_info.join(",")),
);
}
}
if let Ok(top_mem) = ProcessHelper::top_memory_processes(3) {
for (i, proc) in top_mem.iter().enumerate() {
metrics.insert(
format!("top_mem_{}_name", i + 1),
MetricValue::from_string(&proc.name),
);
metrics.insert(
format!("top_mem_{}_mb", i + 1),
MetricValue::Integer((proc.memory_kb / 1024) as i64),
);
}
}
Ok(metrics)
metrics.insert(
"zombie_processes".to_string(),
MetricValue::from_string(zombie_info.join(",")),
);
}
}
fn cleanup(&mut self) -> pscand_core::Result<()> {
Ok(())
if let Ok(top_mem) = ProcessHelper::top_memory_processes(3) {
for (i, proc) in top_mem.iter().enumerate() {
metrics.insert(
format!("top_mem_{}_name", i + 1),
MetricValue::from_string(&proc.name),
);
metrics.insert(
format!("top_mem_{}_mb", i + 1),
MetricValue::Integer((proc.memory_kb / 1024) as i64),
);
}
}
Ok(metrics)
}
fn cleanup(&mut self) -> pscand_core::Result<()> {
Ok(())
}
}