use std::sync::Arc; #[derive(Clone)] pub struct TransportMetrics { pub messages_sent: Arc, pub messages_received: Arc, pub messages_failed: Arc, pub active_connections: Arc, } impl TransportMetrics { pub fn new() -> Self { Self { messages_sent: Arc::new(std::sync::atomic::AtomicU64::new(0)), messages_received: Arc::new(std::sync::atomic::AtomicU64::new(0)), messages_failed: Arc::new(std::sync::atomic::AtomicU64::new(0)), active_connections: Arc::new(std::sync::atomic::AtomicI64::new(0)), } } pub fn increment_sent(&self) { self.messages_sent .fetch_add(1, std::sync::atomic::Ordering::Relaxed); } pub fn increment_received(&self) { self.messages_received .fetch_add(1, std::sync::atomic::Ordering::Relaxed); } pub fn increment_failed(&self) { self.messages_failed .fetch_add(1, std::sync::atomic::Ordering::Relaxed); } pub fn increment_connections(&self) { self.active_connections .fetch_add(1, std::sync::atomic::Ordering::Relaxed); } pub fn decrement_connections(&self) { self.active_connections .fetch_sub(1, std::sync::atomic::Ordering::Relaxed); } }