@@ -3,6 +3,7 @@ package p2p
33import (
44 "strings"
55
6+ "github.com/OffchainLabs/prysm/v6/beacon-chain/p2p/peers"
67 "github.com/libp2p/go-libp2p/core/peer"
78 "github.com/libp2p/go-libp2p/core/peerstore"
89 "github.com/prometheus/client_golang/prometheus"
@@ -26,12 +27,25 @@ var (
2627 Help : "The number of peers in a given state." ,
2728 },
2829 []string {"state" })
30+ p2pMaxPeers = promauto .NewGauge (prometheus.GaugeOpts {
31+ Name : "p2p_max_peers" ,
32+ Help : "The target maximum number of peers." ,
33+ })
34+ p2pPeerCountDirectionType = promauto .NewGaugeVec (prometheus.GaugeOpts {
35+ Name : "p2p_peer_count_direction_type" ,
36+ Help : "The number of peers in a given direction and type." ,
37+ },
38+ []string {"direction" , "type" })
2939 connectedPeersCount = promauto .NewGaugeVec (prometheus.GaugeOpts {
3040 Name : "connected_libp2p_peers" ,
3141 Help : "Tracks the total number of connected libp2p peers by agent string" ,
3242 },
3343 []string {"agent" },
3444 )
45+ minimumPeersPerSubnet = promauto .NewGauge (prometheus.GaugeOpts {
46+ Name : "p2p_minimum_peers_per_subnet" ,
47+ Help : "The minimum number of peers to connect to per subnet" ,
48+ })
3549 avgScoreConnectedClients = promauto .NewGaugeVec (prometheus.GaugeOpts {
3650 Name : "connected_libp2p_peers_average_scores" ,
3751 Help : "Tracks the overall p2p scores of connected libp2p peers by agent string" ,
@@ -174,35 +188,45 @@ var (
174188)
175189
176190func (s * Service ) updateMetrics () {
191+ store := s .Host ().Peerstore ()
177192 connectedPeers := s .peers .Connected ()
193+
178194 p2pPeerCount .WithLabelValues ("Connected" ).Set (float64 (len (connectedPeers )))
179195 p2pPeerCount .WithLabelValues ("Disconnected" ).Set (float64 (len (s .peers .Disconnected ())))
180196 p2pPeerCount .WithLabelValues ("Connecting" ).Set (float64 (len (s .peers .Connecting ())))
181197 p2pPeerCount .WithLabelValues ("Disconnecting" ).Set (float64 (len (s .peers .Disconnecting ())))
182198 p2pPeerCount .WithLabelValues ("Bad" ).Set (float64 (len (s .peers .Bad ())))
183199
184- store := s .Host ().Peerstore ()
185- numConnectedPeersByClient := make (map [string ]float64 )
200+ upperTCP := strings .ToUpper (string (peers .TCP ))
201+ upperQUIC := strings .ToUpper (string (peers .QUIC ))
202+
203+ p2pPeerCountDirectionType .WithLabelValues ("inbound" , upperTCP ).Set (float64 (len (s .peers .InboundConnectedWithProtocol (peers .TCP ))))
204+ p2pPeerCountDirectionType .WithLabelValues ("inbound" , upperQUIC ).Set (float64 (len (s .peers .InboundConnectedWithProtocol (peers .QUIC ))))
205+ p2pPeerCountDirectionType .WithLabelValues ("outbound" , upperTCP ).Set (float64 (len (s .peers .OutboundConnectedWithProtocol (peers .TCP ))))
206+ p2pPeerCountDirectionType .WithLabelValues ("outbound" , upperQUIC ).Set (float64 (len (s .peers .OutboundConnectedWithProtocol (peers .QUIC ))))
207+
208+ connectedPeersCountByClient := make (map [string ]float64 )
186209 peerScoresByClient := make (map [string ][]float64 )
187- for i := 0 ; i < len (connectedPeers ); i ++ {
188- p := connectedPeers [i ]
210+ for _ , p := range connectedPeers {
189211 pid , err := peer .Decode (p .String ())
190212 if err != nil {
191213 log .WithError (err ).Debug ("Could not decode peer string" )
192214 continue
193215 }
194216
195217 foundName := agentFromPid (pid , store )
196- numConnectedPeersByClient [foundName ] += 1
218+ connectedPeersCountByClient [foundName ] += 1
197219
198220 // Get peer scoring data.
199221 overallScore := s .peers .Scorers ().Score (pid )
200222 peerScoresByClient [foundName ] = append (peerScoresByClient [foundName ], overallScore )
201223 }
224+
202225 connectedPeersCount .Reset () // Clear out previous results.
203- for agent , total := range numConnectedPeersByClient {
226+ for agent , total := range connectedPeersCountByClient {
204227 connectedPeersCount .WithLabelValues (agent ).Set (total )
205228 }
229+
206230 avgScoreConnectedClients .Reset () // Clear out previous results.
207231 for agent , scoringData := range peerScoresByClient {
208232 avgScore := average (scoringData )
0 commit comments