Hi all,
I’m working on a Rust project using rust-libp2p and trying to instrument my network with bandwidth metrics. I’m using the BandwidthTransport wrapper around my transport and have set up a prometheus_client::Registry to collect metrics.
Here is what I have so far:
-
I create my base transport (TCP + Noise + Yamux).
-
I wrap it with
BandwidthTransport::new(transport, &mut registry). -
I then create a
Swarmusing this bandwidth-wrapped transport.
My goal is to periodically read bandwidth stats (sent/received bytes, rates, etc.) from the Metrics associated with the BandwidthTransport and output them (e.g., log or expose via Prometheus).
I’m struggling with:
-
How exactly to access the bandwidth stats from
MetricsorBandwidthTransportafter the swarm is running. -
How to properly integrate this with
SwarmBuilder::with_bandwidth_metrics()if I want to use it. -
Any examples or idiomatic ways to expose or print bandwidth usage in runtime.
I haven’t found clear examples or docs on how to read and output these bandwidth metrics at runtime.
Could anyone provide guidance, example snippets, or best practices for:
-
Accessing current bandwidth stats from the swarm or metrics instance.
-
Integrating
BandwidthTransportwithSwarmBuilder::with_bandwidth_metrics(). -
Exposing or logging bandwidth data during the swarm event loop.
Thanks in advance for any help!