pub struct PeerBandwidthMonitor {
pub windows: HashMap<String, PeerBandwidthWindow>,
pub config: MonitorConfig,
pub stats: BandwidthMonitorStats,
pub pending_anomalies: Vec<BandwidthAnomaly>,
}Expand description
Tracks per-peer and aggregate bandwidth over a sliding tick window.
Call record on each tick per peer.
Spike anomalies are appended to pending_anomalies and can be retrieved
with drain_anomalies.
Idle anomalies are computed on demand via
check_idle.
Fields§
§windows: HashMap<String, PeerBandwidthWindow>Per-peer sliding windows, keyed by peer_id.
config: MonitorConfigMonitor configuration.
stats: BandwidthMonitorStatsAggregate statistics.
pending_anomalies: Vec<BandwidthAnomaly>Anomalies detected during record calls; cleared by drain_anomalies.
Implementations§
Source§impl PeerBandwidthMonitor
impl PeerBandwidthMonitor
Sourcepub fn new(config: MonitorConfig) -> Self
pub fn new(config: MonitorConfig) -> Self
Create a new monitor with the given configuration.
Sourcepub fn record(
&mut self,
peer_id: &str,
tick: u64,
bytes_sent: u64,
bytes_recv: u64,
)
pub fn record( &mut self, peer_id: &str, tick: u64, bytes_sent: u64, bytes_recv: u64, )
Record a bandwidth sample for peer_id at logical tick.
Automatically creates a window entry for new peers. After recording,
checks for send/receive spikes and appends any detected
BandwidthAnomaly to pending_anomalies.
Sourcepub fn drain_anomalies(&mut self) -> Vec<BandwidthAnomaly>
pub fn drain_anomalies(&mut self) -> Vec<BandwidthAnomaly>
Take all pending anomalies, leaving an empty list.
Sourcepub fn check_idle(&mut self, current_tick: u64) -> Vec<BandwidthAnomaly>
pub fn check_idle(&mut self, current_tick: u64) -> Vec<BandwidthAnomaly>
Scan all tracked peers for idle conditions at current_tick.
A peer is idle when it has no samples in its window or its most
recent sample tick is more than idle_threshold_ticks behind
current_tick.
Unlike spike detection, idle anomalies are returned directly and
are NOT added to pending_anomalies.
Sourcepub fn peer_window(&self, peer_id: &str) -> Option<&PeerBandwidthWindow>
pub fn peer_window(&self, peer_id: &str) -> Option<&PeerBandwidthWindow>
Return a shared reference to the sliding window for peer_id, if any.
Sourcepub fn stats(&self) -> &BandwidthMonitorStats
pub fn stats(&self) -> &BandwidthMonitorStats
Return a shared reference to the aggregate statistics.
Auto Trait Implementations§
impl Freeze for PeerBandwidthMonitor
impl RefUnwindSafe for PeerBandwidthMonitor
impl Send for PeerBandwidthMonitor
impl Sync for PeerBandwidthMonitor
impl Unpin for PeerBandwidthMonitor
impl UnsafeUnpin for PeerBandwidthMonitor
impl UnwindSafe for PeerBandwidthMonitor
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more