mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-09-27 04:26:41 +08:00
rcmgr: register prometheus metrics with the libp2p registerer (#2370)
* rcmgr: register prometheus metrics with the libp2p registerer * update dashboard readme
This commit is contained in:
@@ -26,6 +26,7 @@ import (
|
|||||||
blankhost "github.com/libp2p/go-libp2p/p2p/host/blank"
|
blankhost "github.com/libp2p/go-libp2p/p2p/host/blank"
|
||||||
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
|
"github.com/libp2p/go-libp2p/p2p/host/eventbus"
|
||||||
"github.com/libp2p/go-libp2p/p2p/host/peerstore/pstoremem"
|
"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"
|
routed "github.com/libp2p/go-libp2p/p2p/host/routed"
|
||||||
"github.com/libp2p/go-libp2p/p2p/net/swarm"
|
"github.com/libp2p/go-libp2p/p2p/net/swarm"
|
||||||
tptu "github.com/libp2p/go-libp2p/p2p/net/upgrader"
|
tptu "github.com/libp2p/go-libp2p/p2p/net/upgrader"
|
||||||
@@ -299,6 +300,10 @@ func (cfg *Config) NewNode() (host.Host, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !cfg.DisableMetrics {
|
||||||
|
rcmgrObs.MustRegisterWith(cfg.PrometheusRegisterer)
|
||||||
|
}
|
||||||
|
|
||||||
h, err := bhost.NewHost(swrm, &bhost.HostOpts{
|
h, err := bhost.NewHost(swrm, &bhost.HostOpts{
|
||||||
EventBus: eventBus,
|
EventBus: eventBus,
|
||||||
ConnManager: cfg.ConnManager,
|
ConnManager: cfg.ConnManager,
|
||||||
|
@@ -5,8 +5,10 @@ import follow the Grafana docs [here](https://grafana.com/docs/grafana/latest/da
|
|||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
To make sure you're emitting the correct metrics you'll have to register the
|
To make sure you're emitting the metrics you'll have to create the Resource
|
||||||
metrics with a Prometheus Registerer. For example:
|
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
|
``` go
|
||||||
import (
|
import (
|
||||||
@@ -18,8 +20,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func SetupResourceManager() (network.ResourceManager, error) {
|
func SetupResourceManager() (network.ResourceManager, error) {
|
||||||
rcmgrObs.MustRegisterWith(prometheus.DefaultRegisterer)
|
|
||||||
|
|
||||||
str, err := rcmgrObs.NewStatsTraceReporter()
|
str, err := rcmgrObs.NewStatsTraceReporter()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@@ -142,7 +142,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func MustRegisterWith(reg prometheus.Registerer) {
|
func MustRegisterWith(reg prometheus.Registerer) {
|
||||||
reg.MustRegister(
|
metricshelper.RegisterCollectors(reg,
|
||||||
conns,
|
conns,
|
||||||
peerConns,
|
peerConns,
|
||||||
previousPeerConns,
|
previousPeerConns,
|
||||||
|
Reference in New Issue
Block a user