Skip to content

Commit 767001e

Browse files
committed
feat(stats): calculate packet rates
Signed-off-by: Sergey Matov <[email protected]>
1 parent 4329dde commit 767001e

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

stats/src/dpstats.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
//! Implements a packet stats sink.
66
7+
use crate::rate::Derivative;
78
use net::packet::Packet;
89
use pipeline::NetworkFunction;
910

@@ -257,6 +258,50 @@ impl StatsCollector {
257258
});
258259
self.submitted.push(concluded.vpc);
259260

261+
let filters_by_src: hashbrown::HashMap<
262+
VpcDiscriminant,
263+
TransmitSummary<SavitzkyGolayFilter<u64>>,
264+
> = (&self.submitted).into();
265+
if let Ok(rates_by_src) =
266+
<hashbrown::HashMap<_, TransmitSummary<SavitzkyGolayFilter<u64>>>>::derivative(
267+
&filters_by_src,
268+
)
269+
{
270+
rates_by_src.iter().for_each(|(&src, tx_summary)| {
271+
let metrics = match self.metrics.get(&src) {
272+
None => {
273+
warn!("lost metrics for src {src}");
274+
return;
275+
}
276+
Some(metrics) => metrics,
277+
};
278+
tx_summary.dst.iter().for_each(|(dst, rate)| {
279+
if let Some(action) = metrics.peering.get(dst) {
280+
action.tx.packet.rate.metric.set(rate.packets);
281+
action.tx.byte.rate.metric.set(rate.bytes);
282+
} else {
283+
warn!("lost metrics for src {src} to dst {dst}");
284+
}
285+
});
286+
});
287+
288+
/* /// This is original code I wrote to set the rates in the metrics.
289+
for (src, tx_summary) in rates_by_src {
290+
let Some(metrics) = self.metrics.get(&src) else {
291+
warn!("lost metrics for src {src}");
292+
continue;
293+
};
294+
for (dst, rate) in tx_summary.dst {
295+
if let Some(action) = metrics.peering.get(&dst) {
296+
action.tx.packet.rate.metric.set(rate.packets);
297+
action.tx.byte.rate.metric.set(rate.bytes);
298+
} else {
299+
warn!("lost metrics for src {src} to dst {dst}");
300+
}
301+
}
302+
}*/
303+
}
304+
260305
// TODO: add in rate calculations
261306
// TODO: add in drop metrics
262307
}

0 commit comments

Comments
 (0)