Skip to main content

WsStats

Struct WsStats 

Source
pub struct WsStats {
    pub total_messages_received: u64,
    pub total_bytes_received: u64,
}
Expand description

Statistics collected during WebSocket operation.

Fields§

§total_messages_received: u64

Total number of messages received (text + binary combined).

§total_bytes_received: u64

Total bytes received across all messages.

Implementations§

Source§

impl WsStats

Source

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).

Source

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.

Source

pub fn avg_message_size(&self) -> Option<f64>

👎Deprecated since 2.2.0:

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).

Source

pub fn total_data_mb(&self) -> f64

Total bytes received expressed as mebibytes (MiB): total_bytes / 1_048_576.0.

Source

pub fn total_data_kb(&self) -> f64

Total bytes received expressed as kibibytes (KiB): total_bytes / 1_024.0.

Source

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).

Source

pub fn messages_per_byte(&self) -> Option<f64>

👎Deprecated since 2.2.0:

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.

Source

pub fn avg_message_size_bytes(&self) -> Option<f64>

👎Deprecated since 2.2.0:

Use bytes_per_message() instead

Average bytes per message received.

Returns None if no messages have been received.

Source

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.

Source

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.

Source

pub fn has_traffic(&self) -> bool

Returns true if at least one message has been received.

Source

pub fn is_high_volume(&self, threshold: u64) -> bool

Returns true if total_messages_received >= threshold.

Source

pub fn average_message_size_bytes(&self) -> Option<f64>

👎Deprecated since 2.2.0:

Use bytes_per_message() instead

Average message size in bytes: alias for bytes_per_message.

Returns None if no messages have been received yet.

Source

pub fn bytes_per_message(&self) -> Option<f64>

Average bytes per message received so far.

Returns None if no messages have been received yet.

Source

pub fn total_data_gb(&self) -> f64

Total bytes received expressed as gibibytes (GiB): total_bytes / 1_073_741_824.0.

Source

pub fn is_active(&self, min_messages: u64) -> bool

Returns true if at least min_messages have been received.

Source

pub fn has_received_bytes(&self) -> bool

Returns true if any bytes have been received.

Source

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.

Source

pub fn message_density(&self, elapsed_ms: u64) -> f64

👎Deprecated since 2.2.0:

Use message_rate() instead

Messages received per second over elapsed_ms: alias for message_rate.

Returns 0.0 if elapsed_ms is zero.

Source

pub fn compression_ratio(&self) -> Option<f64>

👎Deprecated since 2.2.0:

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.

Source

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.

Trait Implementations§

Source§

impl Clone for WsStats

Source§

fn clone(&self) -> WsStats

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WsStats

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for WsStats

Source§

fn default() -> WsStats

Returns the “default value” for a type. Read more
Source§

impl Copy for WsStats

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more