libp2p / rust-libp2p

The Rust Implementation of the libp2p networking stack.
https://libp2p.io
MIT License
4.58k stars 953 forks source link

misc/metrics: Expose bytes send/received per protocol #3262

Open mxinden opened 1 year ago

mxinden commented 1 year ago

Description

Expose Prometheus metrics counting the number of bytes send and received on streams per protocol.

Rough idea:

libp2p_bytes { direction = "in", protocol = "/ipfs/kad/1.0.0" } 42
libp2p_bytes { direction = "out", protocol = "/ipfs/kad/1.0.0" } 42

Motivation

Allows us to get an intuition of the bandwidth consumption of each of the libp2p protocols.

Requirements

  1. Use https://github.com/libp2p/rust-libp2p/pull/3261
  2. Implement Collector trait from https://github.com/prometheus/client_rust/pull/82

Open questions

Are you planning to do it yourself in a pull request?

Not any time soon. Help is much appreciated.

thomaseizinger commented 1 year ago

Do you have a vision for how to implement this without adding a dependency onto prometheus directly to libp2p-swarm?

mxinden commented 1 year ago

We can use https://github.com/libp2p/rust-libp2p/pull/3180 in combination with the upcoming Prometheus Collector abstraction https://github.com/prometheus/client_rust/pull/82.

thomaseizinger commented 1 year ago

https://github.com/libp2p/rust-libp2p/pull/3180 did not introduce a separation per stream though only a sum across all streams. Also, I am not yet sure how we will be able to associate the protocol with the stream because that one is only available before we inject it into the ConnectionHandler at a point where the stream has already been handed off from the muxer.