Skip to content

Commit 2b8741f

Browse files
committed
Collect peer info metrics in p2p
1 parent e6640c0 commit 2b8741f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

rolling-shutter/p2p/dht.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func findPeers(ctx context.Context, h host.Host, d discovery.Discoverer, ns stri
8787
newConnections := 0
8888
failedDials := 0
8989
for _, p := range peers {
90+
collectPeerAddresses(p)
9091
if p.ID == h.ID() {
9192
continue
9293
}

rolling-shutter/p2p/metrics.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package p2p
22

3-
import "github.com/prometheus/client_golang/prometheus"
3+
import (
4+
"github.com/libp2p/go-libp2p/core/peer"
5+
"github.com/prometheus/client_golang/prometheus"
6+
)
47

58
var metricsP2PMessageValidationTime = prometheus.NewHistogramVec(
69
prometheus.HistogramOpts{
@@ -24,7 +27,23 @@ var metricsP2PMessageHandlingTime = prometheus.NewHistogramVec(
2427
[]string{"topic"},
2528
)
2629

30+
var metricsP2PPeerTuples = prometheus.NewGaugeVec(
31+
prometheus.GaugeOpts{
32+
Namespace: "shutter",
33+
Subsystem: "p2p",
34+
Name: "dialed_peer",
35+
Help: "Collection of the encountered peer tuples",
36+
},
37+
[]string{"peer_id", "peer_ip"})
38+
39+
func collectPeerAddresses(peer peer.AddrInfo) {
40+
for _, multiAddr := range peer.Addrs {
41+
metricsP2PPeerTuples.WithLabelValues(peer.ID.String(), multiAddr.String()).Add(1)
42+
}
43+
}
44+
2745
func init() {
2846
prometheus.MustRegister(metricsP2PMessageValidationTime)
2947
prometheus.MustRegister(metricsP2PMessageHandlingTime)
48+
prometheus.MustRegister(metricsP2PPeerTuples)
3049
}

0 commit comments

Comments
 (0)