From f7d33fba7a2ebaca294751433b36514c166c7222 Mon Sep 17 00:00:00 2001 From: Lev Kokotov Date: Tue, 16 Aug 2022 15:00:31 -0700 Subject: [PATCH] Log stats-own generated events --- src/stats.rs | 48 ++++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/src/stats.rs b/src/stats.rs index fde4071..773140b 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -305,6 +305,24 @@ impl Collector { Collector { rx, tx } } + fn send(tx: &Sender, event: Event) { + let name = event.name; + let result = tx.try_send(event); + + match result { + Ok(_) => trace!( + "{:?} event reported successfully, capacity: {}", + name, + tx.capacity() + ), + + Err(err) => match err { + TrySendError::Full { .. } => error!("{:?} event dropped, buffer full", name), + TrySendError::Closed { .. } => error!("{:?} event dropped, channel closed", name), + }, + }; + } + /// The statistics collection handler. It will collect statistics /// for `address_id`s starting at 0 up to `addresses`. pub async fn collect(&mut self) { @@ -354,12 +372,15 @@ impl Collector { interval.tick().await; let address_count = get_number_of_addresses(); for address_id in 0..address_count { - let _ = tx.try_send(Event { - name: EventName::UpdateStats, - value: 0, - process_id: -1, - address_id: address_id, - }); + Self::send( + &tx, + Event { + name: EventName::UpdateStats, + value: 0, + process_id: -1, + address_id: address_id, + }, + ); } } }); @@ -372,12 +393,15 @@ impl Collector { interval.tick().await; let address_count = get_number_of_addresses(); for address_id in 0..address_count { - let _ = tx.try_send(Event { - name: EventName::UpdateAverages, - value: 0, - process_id: -1, - address_id: address_id, - }); + Self::send( + &tx, + Event { + name: EventName::UpdateAverages, + value: 0, + process_id: -1, + address_id: address_id, + }, + ); } } });