pub struct ProtocolMetrics {
pub connections_total: AtomicU64,
pub connections_active: AtomicU64,
pub messages_total: AtomicU64,
pub errors_total: AtomicU64,
pub bytes_sent: AtomicU64,
pub bytes_received: AtomicU64,
pub latency_micros: AtomicU64,
}Expand description
Generic metrics collector shared by all protocol crates.
Contains the common counters that every protocol needs. Protocol crates can embed this struct and add protocol-specific fields alongside it.
Fields§
§connections_total: AtomicU64Total number of connections ever established
connections_active: AtomicU64Currently active connections
messages_total: AtomicU64Total messages processed (sent or received, depending on protocol)
errors_total: AtomicU64Total errors encountered
bytes_sent: AtomicU64Total bytes sent
bytes_received: AtomicU64Total bytes received
latency_micros: AtomicU64Average latency in microseconds (simple moving average)
Implementations§
Source§impl ProtocolMetrics
impl ProtocolMetrics
Sourcepub fn record_connection(&self)
pub fn record_connection(&self)
Record a new connection (increments both total and active).
Sourcepub fn record_disconnection(&self)
pub fn record_disconnection(&self)
Record a disconnection (decrements active connections).
Sourcepub fn record_message(&self)
pub fn record_message(&self)
Record a message processed.
Sourcepub fn record_messages(&self, count: u64)
pub fn record_messages(&self, count: u64)
Record multiple messages processed at once.
Sourcepub fn record_error(&self)
pub fn record_error(&self)
Record an error.
Sourcepub fn record_bytes_sent(&self, bytes: u64)
pub fn record_bytes_sent(&self, bytes: u64)
Record bytes sent.
Sourcepub fn record_bytes_received(&self, bytes: u64)
pub fn record_bytes_received(&self, bytes: u64)
Record bytes received.
Sourcepub fn record_latency(&self, latency_micros: u64)
pub fn record_latency(&self, latency_micros: u64)
Record latency in microseconds (simple moving average).
Sourcepub fn snapshot(&self) -> ProtocolMetricsSnapshot
pub fn snapshot(&self) -> ProtocolMetricsSnapshot
Take a point-in-time snapshot of all counters.
Sourcepub fn export_prometheus(&self, prefix: &str) -> String
pub fn export_prometheus(&self, prefix: &str) -> String
Export common metrics in Prometheus format with a given protocol prefix.
§Arguments
prefix- Protocol name for metric labels (e.g., “kafka”, “mqtt”)