From cd47cadc8847d0be2cb2338dee5dae2c50d7419a Mon Sep 17 00:00:00 2001 From: sukun Date: Thu, 15 Jun 2023 15:47:53 +0530 Subject: [PATCH 1/2] rcmgr: register prometheus metrics with the libp2p registerer --- config/config.go | 5 +++++ p2p/host/resource-manager/obs/stats.go | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 25f70a5f65..fb082fbad9 100644 --- a/config/config.go +++ b/config/config.go @@ -26,6 +26,7 @@ import ( blankhost "github.com/libp2p/go-libp2p/p2p/host/blank" "github.com/libp2p/go-libp2p/p2p/host/eventbus" "github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem" + rcmgrObs "github.com/libp2p/go-libp2p/p2p/host/resource-manager/obs" routed "github.com/libp2p/go-libp2p/p2p/host/routed" "github.com/libp2p/go-libp2p/p2p/net/swarm" tptu "github.com/libp2p/go-libp2p/p2p/net/upgrader" @@ -299,6 +300,10 @@ func (cfg *Config) NewNode() (host.Host, error) { return nil, err } + if !cfg.DisableMetrics { + rcmgrObs.MustRegisterWith(cfg.PrometheusRegisterer) + } + h, err := bhost.NewHost(swrm, &bhost.HostOpts{ EventBus: eventBus, ConnManager: cfg.ConnManager, diff --git a/p2p/host/resource-manager/obs/stats.go b/p2p/host/resource-manager/obs/stats.go index bae3f09981..3362d70e31 100644 --- a/p2p/host/resource-manager/obs/stats.go +++ b/p2p/host/resource-manager/obs/stats.go @@ -142,7 +142,7 @@ var ( ) func MustRegisterWith(reg prometheus.Registerer) { - reg.MustRegister( + metricshelper.RegisterCollectors(reg, conns, peerConns, previousPeerConns, From f19ea3fea020b419762a72b70e322a268cfa4e58 Mon Sep 17 00:00:00 2001 From: sukun Date: Thu, 15 Jun 2023 16:33:59 +0530 Subject: [PATCH 2/2] update dashboard readme --- dashboards/resource-manager/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/dashboards/resource-manager/README.md b/dashboards/resource-manager/README.md index 6915c0e6d9..cfcc6d3fd7 100644 --- a/dashboards/resource-manager/README.md +++ b/dashboards/resource-manager/README.md @@ -5,8 +5,10 @@ import follow the Grafana docs [here](https://grafana.com/docs/grafana/latest/da ## Setup -To make sure you're emitting the correct metrics you'll have to register the -metrics with a Prometheus Registerer. For example: +To make sure you're emitting the metrics you'll have to create the Resource +Manager with a StatsTraceReporter. By default metrics will be sent to +prometheus.DefaultRegisterer. To use a different Registerer use the libp2p +option libp2p.PrometheusRegisterer. For example: ``` go import ( @@ -18,8 +20,6 @@ import ( ) func SetupResourceManager() (network.ResourceManager, error) { - rcmgrObs.MustRegisterWith(prometheus.DefaultRegisterer) - str, err := rcmgrObs.NewStatsTraceReporter() if err != nil { return nil, err