pub struct WsStats {
pub total_messages_received: u64,
pub total_bytes_received: u64,
}Expand description
Statistics collected during WebSocket operation.
Fields§
§total_messages_received: u64Total number of messages received (text + binary combined).
total_bytes_received: u64Total bytes received across all messages.
Implementations§
Source§impl WsStats
impl WsStats
Sourcepub fn message_rate(&self, elapsed_ms: u64) -> f64
pub fn message_rate(&self, elapsed_ms: u64) -> f64
Messages per second over the given elapsed window.
Returns 0.0 if elapsed_ms is zero (avoids division by zero).
Sourcepub fn byte_rate(&self, elapsed_ms: u64) -> f64
pub fn byte_rate(&self, elapsed_ms: u64) -> f64
Bytes per second over the given elapsed window.
Returns 0.0 if elapsed_ms is zero.
Sourcepub fn avg_message_size(&self) -> Option<f64>
👎Deprecated since 2.2.0: Use bytes_per_message() instead
pub fn avg_message_size(&self) -> Option<f64>
Use bytes_per_message() instead
Average bytes per message: total_bytes / total_messages.
Returns None if no messages have been received (avoids division by zero).
Sourcepub fn total_data_mb(&self) -> f64
pub fn total_data_mb(&self) -> f64
Total bytes received expressed as mebibytes (MiB): total_bytes / 1_048_576.0.
Sourcepub fn total_data_kb(&self) -> f64
pub fn total_data_kb(&self) -> f64
Total bytes received expressed as kibibytes (KiB): total_bytes / 1_024.0.
Sourcepub fn bandwidth_bps(&self, elapsed_ms: u64) -> f64
pub fn bandwidth_bps(&self, elapsed_ms: u64) -> f64
Average received bandwidth in bytes per second over elapsed_ms.
Returns 0.0 when elapsed_ms is zero (avoids division by zero).
Sourcepub fn messages_per_byte(&self) -> Option<f64>
👎Deprecated since 2.2.0: Use efficiency_ratio() instead
pub fn messages_per_byte(&self) -> Option<f64>
Use efficiency_ratio() instead
Average number of messages per byte received.
Returns None when no bytes have been received (avoids division by
zero). A higher value means smaller average message size.
Sourcepub fn avg_message_size_bytes(&self) -> Option<f64>
👎Deprecated since 2.2.0: Use bytes_per_message() instead
pub fn avg_message_size_bytes(&self) -> Option<f64>
Use bytes_per_message() instead
Average bytes per message received.
Returns None if no messages have been received.
Sourcepub fn bandwidth_kbps(&self, elapsed_ms: u64) -> f64
pub fn bandwidth_kbps(&self, elapsed_ms: u64) -> f64
Bits per second received over elapsed_ms (bytes × 8 / seconds).
Returns 0.0 when elapsed_ms is zero.
Sourcepub fn is_idle(&self, elapsed_ms: u64, min_rate: f64) -> bool
pub fn is_idle(&self, elapsed_ms: u64, min_rate: f64) -> bool
Returns true if the current message rate is below min_rate (msgs/s).
Returns true when elapsed_ms is zero (no time elapsed → rate = 0).
Useful for detecting stalled or silent feeds.
Sourcepub fn has_traffic(&self) -> bool
pub fn has_traffic(&self) -> bool
Returns true if at least one message has been received.
Sourcepub fn is_high_volume(&self, threshold: u64) -> bool
pub fn is_high_volume(&self, threshold: u64) -> bool
Returns true if total_messages_received >= threshold.
Sourcepub fn average_message_size_bytes(&self) -> Option<f64>
👎Deprecated since 2.2.0: Use bytes_per_message() instead
pub fn average_message_size_bytes(&self) -> Option<f64>
Use bytes_per_message() instead
Average message size in bytes: alias for bytes_per_message.
Returns None if no messages have been received yet.
Sourcepub fn bytes_per_message(&self) -> Option<f64>
pub fn bytes_per_message(&self) -> Option<f64>
Average bytes per message received so far.
Returns None if no messages have been received yet.
Sourcepub fn total_data_gb(&self) -> f64
pub fn total_data_gb(&self) -> f64
Total bytes received expressed as gibibytes (GiB): total_bytes / 1_073_741_824.0.
Sourcepub fn is_active(&self, min_messages: u64) -> bool
pub fn is_active(&self, min_messages: u64) -> bool
Returns true if at least min_messages have been received.
Sourcepub fn has_received_bytes(&self) -> bool
pub fn has_received_bytes(&self) -> bool
Returns true if any bytes have been received.
Sourcepub fn efficiency_ratio(&self) -> Option<f64>
pub fn efficiency_ratio(&self) -> Option<f64>
Messages per byte received: total_messages / total_bytes.
Higher values indicate smaller average message sizes.
Returns None if no bytes have been received.
Sourcepub fn message_density(&self, elapsed_ms: u64) -> f64
👎Deprecated since 2.2.0: Use message_rate() instead
pub fn message_density(&self, elapsed_ms: u64) -> f64
Use message_rate() instead
Messages received per second over elapsed_ms: alias for message_rate.
Returns 0.0 if elapsed_ms is zero.
Sourcepub fn compression_ratio(&self) -> Option<f64>
👎Deprecated since 2.2.0: Use efficiency_ratio() instead
pub fn compression_ratio(&self) -> Option<f64>
Use efficiency_ratio() instead
Ratio of messages to bytes: useful as a compression proxy.
Higher values indicate smaller, more “compressed” messages.
Returns None if no bytes have been received.
Sourcepub fn uptime_fraction(&self, total_ms: u64) -> f64
pub fn uptime_fraction(&self, total_ms: u64) -> f64
Fraction of total_ms during which the connection was active.
Estimated as total_messages_received / (total_ms / 1000.0 * expected_rate).
Here we use a simple proxy: bytes_received / total_ms (bytes per ms),
normalized so that 0.0 means idle and higher values indicate more activity.
Returns 0.0 if total_ms is zero.