Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rcmgr: register prometheus metrics with the libp2p registerer #2370

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions dashboards/resource-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -18,8 +20,6 @@ import (
)

func SetupResourceManager() (network.ResourceManager, error) {
rcmgrObs.MustRegisterWith(prometheus.DefaultRegisterer)

str, err := rcmgrObs.NewStatsTraceReporter()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion p2p/host/resource-manager/obs/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ var (
)

func MustRegisterWith(reg prometheus.Registerer) {
reg.MustRegister(
metricshelper.RegisterCollectors(reg,
conns,
peerConns,
previousPeerConns,
Expand Down