Skip to main content

AsyncCollector

Trait AsyncCollector 

Source
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
        }
    }
}

Required Associated Types§

Source

type Snapshot: Snapshot

The snapshot type produced by this collector.

Required Methods§

Source

fn collect(&mut self) -> Self::Snapshot

Collect metrics and return a snapshot.

This method may take seconds to complete (heavy I/O). It runs in a background thread, never blocking the UI.

Implementors§