docs: update scanner development guide

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I1968c93cf2d6c8b4f250bd7f88cc45846a6a6964
This commit is contained in:
raf 2026-02-19 01:03:06 +03:00
commit 16672b2ff1
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -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<serde_json::Value, Box<dyn std::error::Error>> {
// 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(())
}
}