pub trait MetricsCollector: Send + Sync {
// Required methods
fn collect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<CustomMetric>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn name(&self) -> &str;
}Expand description
Trait for implementing custom metrics collectors
Allows extending the monitoring system with domain-specific metrics that are collected periodically and included in reports.
§Example Implementation
use async_trait::async_trait;
use anyhow::Result;
use rusty_feeder::provider::metrics::{MetricsCollector, CustomMetric};
use rustc_hash::FxHashMap;
struct LatencyPercentileCollector {
percentiles: Vec<f64>,
}
#[async_trait]
impl MetricsCollector for LatencyPercentileCollector {
async fn collect(&self) -> Result<Vec<CustomMetric>> {
let mut metrics = Vec::new();
let mut tags = FxHashMap::default();
for percentile in &self.percentiles {
tags.insert("percentile".to_string(), percentile.to_string());
metrics.push(CustomMetric {
name: "custom_latency_percentile".to_string(),
value: 1000.0, // Example value
tags: tags.clone(),
timestamp: quanta::Instant::now().as_nanos() as u64,
});
}
Ok(metrics)
}
fn name(&self) -> &str {
"latency_percentile_collector"
}
}Required Methods§
Sourcefn collect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<CustomMetric>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn collect<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Vec<CustomMetric>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Collects custom metrics when invoked by the monitoring system
This method is called periodically to gather custom metrics. Implementations should be efficient as this runs in the monitoring loop.