Skip to content

Commit 1ccb5b2

Browse files
committed
Add peer ping service and metrics
1 parent b25d0b0 commit 1ccb5b2

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

rolling-shutter/p2p/dht.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ func findPeers(ctx context.Context, h host.Host, d discovery.Discoverer, ns stri
9494
continue
9595
}
9696
metricsP2PPeerConnectedness.WithLabelValues(ourId, p.ID.String()).Add(float64(h.Network().Connectedness(p.ID)))
97+
peerPing := h.Peerstore().LatencyEWMA(p.ID)
98+
if peerPing != 0 {
99+
metricsP2PPeerPing.WithLabelValues(ourId, p.ID.String()).Set(peerPing.Seconds())
100+
}
97101
if h.Network().Connectedness(p.ID) != network.Connected {
98102
_, err = h.Network().DialPeer(ctx, p.ID)
99103
if err != nil {

rolling-shutter/p2p/metrics.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ var metricsP2PPeerConnectedness = prometheus.NewGaugeVec(
4545
},
4646
[]string{"our_id", "peer_id"})
4747

48+
var metricsP2PPeerPing = prometheus.NewGaugeVec(
49+
prometheus.GaugeOpts{
50+
Namespace: "shutter",
51+
Subsystem: "p2p",
52+
Name: "peer_ping_time_seconds",
53+
Help: "Collection of the ping time to a peer ID.",
54+
},
55+
[]string{"our_id", "peer_id"},
56+
)
57+
4858
func collectPeerAddresses(p peer.AddrInfo) {
4959
for _, multiAddr := range p.Addrs {
5060
metricsP2PPeerTuples.WithLabelValues(p.ID.String(), multiAddr.String()).Add(1)
@@ -56,4 +66,5 @@ func init() {
5666
prometheus.MustRegister(metricsP2PMessageHandlingTime)
5767
prometheus.MustRegister(metricsP2PPeerTuples)
5868
prometheus.MustRegister(metricsP2PPeerConnectedness)
69+
prometheus.MustRegister(metricsP2PPeerPing)
5970
}

rolling-shutter/p2p/p2p.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ func createHost(
200200
libp2p.ListenAddrs(config.ListenAddrs...),
201201
libp2p.ConnectionManager(connectionManager),
202202
libp2p.ProtocolVersion(protocolVersion),
203+
libp2p.Ping(true),
203204
}
204205

205206
localNetworking := bool(config.Environment == env.EnvironmentLocal)

0 commit comments

Comments
 (0)