docs: update scanner development guide
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I1968c93cf2d6c8b4f250bd7f88cc45846a6a6964
This commit is contained in:
parent
7fdd64c379
commit
16672b2ff1
1 changed files with 22 additions and 7 deletions
|
|
@ -28,21 +28,36 @@ pscand-core = { workspace = true }
|
||||||
## Implementing the `Scanner` trait
|
## Implementing the `Scanner` trait
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
use pscand_core::scanner::Scanner;
|
use std::time::Duration;
|
||||||
|
use pscand_core::scanner::{Scanner, ScannerCollectionResult, MetricValue, Result};
|
||||||
use pscand_macros::scanner;
|
use pscand_macros::scanner;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
pub struct CustomScanner;
|
pub struct CustomScanner;
|
||||||
|
|
||||||
impl Scanner for CustomScanner {
|
impl Scanner for CustomScanner {
|
||||||
fn name(&self) -> &str {
|
fn name(&self) -> &'static str {
|
||||||
"custom"
|
"custom"
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect(&self) -> Result<serde_json::Value, Box<dyn std::error::Error>> {
|
fn interval(&self) -> Duration {
|
||||||
// Collect your metrics
|
Duration::from_secs(5)
|
||||||
Ok(serde_json::json!({
|
}
|
||||||
"value": 42
|
|
||||||
}))
|
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(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue