From 16672b2ff1ff9d42f27b69838bc4e8286431a79f Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Thu, 19 Feb 2026 01:03:06 +0300 Subject: [PATCH] docs: update scanner development guide Signed-off-by: NotAShelf Change-Id: I1968c93cf2d6c8b4f250bd7f88cc45846a6a6964 --- docs/SCANNERS.md | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/docs/SCANNERS.md b/docs/SCANNERS.md index 27471c3..059f43d 100644 --- a/docs/SCANNERS.md +++ b/docs/SCANNERS.md @@ -28,21 +28,36 @@ pscand-core = { workspace = true } ## Implementing the `Scanner` trait ```rust -use pscand_core::scanner::Scanner; +use std::time::Duration; +use pscand_core::scanner::{Scanner, ScannerCollectionResult, MetricValue, Result}; use pscand_macros::scanner; +use std::collections::HashMap; pub struct CustomScanner; impl Scanner for CustomScanner { - fn name(&self) -> &str { + fn name(&self) -> &'static str { "custom" } - fn collect(&self) -> Result> { - // Collect your metrics - Ok(serde_json::json!({ - "value": 42 - })) + fn interval(&self) -> Duration { + Duration::from_secs(5) + } + + fn init(&mut self, _config: &toml::Value) -> Result<()> { + // Initialize your scanner (e.g., open hardware interfaces) + Ok(()) + } + + fn collect(&self) -> ScannerCollectionResult { + let mut metrics = HashMap::new(); + metrics.insert("value".to_string(), MetricValue::from_i64(42)); + Ok(metrics) + } + + fn cleanup(&mut self) -> Result<()> { + // Clean up resources + Ok(()) } }