pub trait AsyncCollector: Send + 'static {
type Snapshot: Snapshot;
// Required method
fn collect(&mut self) -> Self::Snapshot;
}Expand description
Background collector that produces snapshots.
Implement this trait for objects that collect metrics in a background thread. The collector owns all heavy I/O objects (System, Disks, Networks, etc.) and produces lightweight snapshots that can be sent through a channel.
§Example
ⓘ
struct SystemCollector {
system: System,
disks: Disks,
}
impl AsyncCollector for SystemCollector {
type Snapshot = MetricsSnapshot;
fn collect(&mut self) -> MetricsSnapshot {
self.system.refresh_all(); // Heavy I/O
MetricsSnapshot {
cpu_usage: self.system.global_cpu_usage(),
// ... extract other data
}
}
}