Skip to content

Commit fd77a5d

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

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

stats/src/dpstats.rs

Lines changed: 29 additions & 1 deletion
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,7 +258,34 @@ impl StatsCollector {
257258
});
258259
self.submitted.push(concluded.vpc);
259260

260-
// TODO: add in rate calculations
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+
261289
// TODO: add in drop metrics
262290
}
263291
}

0 commit comments

Comments
 (0)