Lip2p metrics - browser

Hi,

I am working on a web application (Vite/Typescript) where we are creating libp2p peers from the application itself.
I would like to capture some metrics but I am not able to find a way to doing that. I did find the interface definition and the node/prometheus implementation, but nothing that could run in a browser.

Is there such support, and, if yes, is there some documentation/examples describing how to do it?

Thank you

Hi @cristian.m I assume you’re referring to js-libp2p/packages/interface/src/metrics at master · libp2p/js-libp2p · GitHub which uses prom-client and is limited to node.js
@achingbrain do you have any suggestions here?

@pshahi I am looking at capturing and sending the libp2p metrics to an OTLP backend. I read some more and I did find the metrics interface which looks to be based on Prometheus metrics. I also found this library which implements everything (GitHub - libp2p/js-libp2p-prometheus-metrics: Collect libp2p metrics for scraping by Prometheus) but which is based on node - in addition to captuing the libp2p metrics, it also attempts to capture node provided metrics (like memory usage) which would not work in a browser.

I’m currently trying to develop my own OTLP based implementation of the libp2p expected interfaces which would allow me to send the data to an OTLP metrics aggregator.

In an ideal world, I would have liked if the lib2p2 lib would expose the metrics as OTLP (which is an open standard) and not Prometheus. As an alternative, it would also be nice if the lib would allow selecting between Prometheus and OTLP.

Hi @cristian.m

thanks for taking a look into our current libp2p metrics implementation but you are right in that it is tailored to node environments. That being said other consumers have raised this in the past and utilized GitHub - weaveworks/promjs for their client.

It’s important to note that our implementation is a wrapper around prom-client at it’s core and so depending on the exact metrics you are trying to capture, you could leverage GitHub - weaveworks/promjs along with our Events API to capture some of these metrics.

But it depends on your use case, what types of metrics are you interested in?

Thank you @maschad. Ideally, I would like to capture all the currently available lib2p2 exposed metrics (not the system metrics). :slight_smile: