github.com/prysmaticlabs/prysm@v1.4.4/beacon-chain/sync/metrics.go (about) 1 package sync 2 3 import ( 4 "fmt" 5 "reflect" 6 "strings" 7 8 "github.com/prometheus/client_golang/prometheus" 9 "github.com/prometheus/client_golang/prometheus/promauto" 10 "github.com/prysmaticlabs/prysm/beacon-chain/p2p" 11 "github.com/prysmaticlabs/prysm/cmd/beacon-chain/flags" 12 pb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1" 13 "github.com/prysmaticlabs/prysm/shared/params" 14 ) 15 16 var ( 17 topicPeerCount = promauto.NewGaugeVec( 18 prometheus.GaugeOpts{ 19 Name: "p2p_topic_peer_count", 20 Help: "The number of peers subscribed to a given topic.", 21 }, []string{"topic"}, 22 ) 23 messageReceivedCounter = promauto.NewCounterVec( 24 prometheus.CounterOpts{ 25 Name: "p2p_message_received_total", 26 Help: "Count of messages received.", 27 }, 28 []string{"topic"}, 29 ) 30 messageFailedValidationCounter = promauto.NewCounterVec( 31 prometheus.CounterOpts{ 32 Name: "p2p_message_failed_validation_total", 33 Help: "Count of messages that failed validation.", 34 }, 35 []string{"topic"}, 36 ) 37 messageFailedProcessingCounter = promauto.NewCounterVec( 38 prometheus.CounterOpts{ 39 Name: "p2p_message_failed_processing_total", 40 Help: "Count of messages that passed validation but failed processing.", 41 }, 42 []string{"topic"}, 43 ) 44 numberOfTimesResyncedCounter = promauto.NewCounter( 45 prometheus.CounterOpts{ 46 Name: "number_of_times_resynced", 47 Help: "Count the number of times a node resyncs.", 48 }, 49 ) 50 51 arrivalBlockPropagationHistogram = promauto.NewHistogram( 52 prometheus.HistogramOpts{ 53 Name: "block_arrival_latency_milliseconds", 54 Help: "Captures blocks propagation time. Blocks arrival in milliseconds distribution", 55 Buckets: []float64{250, 500, 1000, 1500, 2000, 4000, 8000, 16000}, 56 }, 57 ) 58 ) 59 60 func (s *Service) updateMetrics() { 61 // do not update metrics if genesis time 62 // has not been initialized 63 if s.cfg.Chain.GenesisTime().IsZero() { 64 return 65 } 66 // We update the dynamic subnet topics. 67 digest, err := s.forkDigest() 68 if err != nil { 69 log.WithError(err).Debugf("Could not compute fork digest") 70 } 71 indices := s.aggregatorSubnetIndices(s.cfg.Chain.CurrentSlot()) 72 attTopic := p2p.GossipTypeMapping[reflect.TypeOf(&pb.Attestation{})] 73 attTopic += s.cfg.P2P.Encoding().ProtocolSuffix() 74 if flags.Get().SubscribeToAllSubnets { 75 for i := uint64(0); i < params.BeaconNetworkConfig().AttestationSubnetCount; i++ { 76 formattedTopic := fmt.Sprintf(attTopic, digest, i) 77 topicPeerCount.WithLabelValues(formattedTopic).Set(float64(len(s.cfg.P2P.PubSub().ListPeers(formattedTopic)))) 78 } 79 } else { 80 for _, committeeIdx := range indices { 81 formattedTopic := fmt.Sprintf(attTopic, digest, committeeIdx) 82 topicPeerCount.WithLabelValues(formattedTopic).Set(float64(len(s.cfg.P2P.PubSub().ListPeers(formattedTopic)))) 83 } 84 } 85 86 // We update all other gossip topics. 87 for topic := range p2p.GossipTopicMappings { 88 // We already updated attestation subnet topics. 89 if strings.Contains(topic, "beacon_attestation") { 90 continue 91 } 92 topic += s.cfg.P2P.Encoding().ProtocolSuffix() 93 if !strings.Contains(topic, "%x") { 94 topicPeerCount.WithLabelValues(topic).Set(float64(len(s.cfg.P2P.PubSub().ListPeers(topic)))) 95 continue 96 } 97 formattedTopic := fmt.Sprintf(topic, digest) 98 topicPeerCount.WithLabelValues(formattedTopic).Set(float64(len(s.cfg.P2P.PubSub().ListPeers(formattedTopic)))) 99 } 100 }