use blueprint_std::{collections::HashMap, sync::Arc};
use tokio::sync::RwLock;
pub struct MetricsCollector {
metrics: Arc<RwLock<HashMap<String, f64>>>,
}
impl MetricsCollector {
pub fn new() -> Self {
Self {
metrics: Arc::new(RwLock::new(HashMap::new())),
}
}
pub async fn record(&self, name: &str, value: f64) {
let mut metrics = self.metrics.write().await;
metrics.insert(name.to_string(), value);
}
pub async fn get_metrics(&self) -> HashMap<String, f64> {
let metrics = self.metrics.read().await;
metrics.clone()
}
pub async fn get_all_metrics(&self) -> HashMap<String, f64> {
self.get_metrics().await
}
}
impl Default for MetricsCollector {
fn default() -> Self {
Self::new()
}
}