Help with collecting bandwidth stats using BandwidthTransport in Rust-libp2p #6110
-
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 Swarm using 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 Metrics or BandwidthTransport after 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 BandwidthTransport with SwarmBuilder::with_bandwidth_metrics(). Exposing or logging bandwidth data during the swarm event loop. I can share part of my code if it is possible Thanks in advance for any help! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Hi, have you looked into the metrics example? |
Beta Was this translation helpful? Give feedback.
see https://github.com/libp2p/rust-libp2p/tree/master/examples/metrics#opentelemetry