github.com/amazechain/amc@v0.1.3/internal/sync/metrics.go (about)

     1  package sync
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/amazechain/amc/internal/p2p"
     6  	"github.com/amazechain/amc/log"
     7  	"strings"
     8  
     9  	"github.com/prometheus/client_golang/prometheus"
    10  	"github.com/prometheus/client_golang/prometheus/promauto"
    11  )
    12  
    13  var (
    14  	topicPeerCount = promauto.NewGaugeVec(
    15  		prometheus.GaugeOpts{
    16  			Name: "p2p_topic_peer_count",
    17  			Help: "The number of peers subscribed to a given topic.",
    18  		}, []string{"topic"},
    19  	)
    20  	subscribedTopicPeerCount = promauto.NewGaugeVec(
    21  		prometheus.GaugeOpts{
    22  			Name: "p2p_subscribed_topic_peer_total",
    23  			Help: "The number of peers subscribed to topics that a host node is also subscribed to.",
    24  		}, []string{"topic"},
    25  	)
    26  	messageReceivedCounter = promauto.NewCounterVec(
    27  		prometheus.CounterOpts{
    28  			Name: "p2p_message_received_total",
    29  			Help: "Count of messages received.",
    30  		},
    31  		[]string{"topic"},
    32  	)
    33  	messageFailedValidationCounter = promauto.NewCounterVec(
    34  		prometheus.CounterOpts{
    35  			Name: "p2p_message_failed_validation_total",
    36  			Help: "Count of messages that failed validation.",
    37  		},
    38  		[]string{"topic"},
    39  	)
    40  	messageIgnoredValidationCounter = promauto.NewCounterVec(
    41  		prometheus.CounterOpts{
    42  			Name: "p2p_message_ignored_validation_total",
    43  			Help: "Count of messages that were ignored in validation.",
    44  		},
    45  		[]string{"topic"},
    46  	)
    47  	messageFailedProcessingCounter = promauto.NewCounterVec(
    48  		prometheus.CounterOpts{
    49  			Name: "p2p_message_failed_processing_total",
    50  			Help: "Count of messages that passed validation but failed processing.",
    51  		},
    52  		[]string{"topic"},
    53  	)
    54  	numberOfTimesResyncedCounter = promauto.NewCounter(
    55  		prometheus.CounterOpts{
    56  			Name: "number_of_times_resynced",
    57  			Help: "Count the number of times a node resyncs.",
    58  		},
    59  	)
    60  	duplicatesRemovedCounter = promauto.NewCounter(
    61  		prometheus.CounterOpts{
    62  			Name: "number_of_duplicates_removed",
    63  			Help: "Count the number of times a duplicate signature set has been removed.",
    64  		},
    65  	)
    66  	numberOfSetsAggregated = promauto.NewHistogram(
    67  		prometheus.HistogramOpts{
    68  			Name:    "number_of_sets_aggregated",
    69  			Help:    "Count the number of times different sets have been successfully aggregated in a batch.",
    70  			Buckets: []float64{10, 50, 100, 200, 400, 800, 1600, 3200},
    71  		},
    72  	)
    73  	rpcBlocksByRangeResponseLatency = promauto.NewHistogram(
    74  		prometheus.HistogramOpts{
    75  			Name:    "rpc_blocks_by_range_response_latency_milliseconds",
    76  			Help:    "Captures total time to respond to rpc blocks by range requests in a milliseconds distribution",
    77  			Buckets: []float64{5, 10, 50, 100, 150, 250, 500, 1000, 2000},
    78  		},
    79  	)
    80  	arrivalBlockPropagationHistogram = promauto.NewHistogram(
    81  		prometheus.HistogramOpts{
    82  			Name:    "block_arrival_latency_milliseconds",
    83  			Help:    "Captures blocks propagation time. Blocks arrival in milliseconds distribution",
    84  			Buckets: []float64{100, 250, 500, 750, 1000, 1500, 2000, 4000, 8000, 12000, 16000, 20000, 24000},
    85  		},
    86  	)
    87  	arrivalBlockPropagationGauge = promauto.NewGauge(prometheus.GaugeOpts{
    88  		Name: "block_arrival_latency_milliseconds_gauge",
    89  		Help: "Captures blocks propagation time. Blocks arrival in milliseconds",
    90  	})
    91  
    92  	// Attestation processing granular error tracking.
    93  	attBadBlockCount = promauto.NewCounter(prometheus.CounterOpts{
    94  		Name: "gossip_attestation_bad_block_total",
    95  		Help: "Increased when a gossip attestation references a bad block",
    96  	})
    97  	attBadLmdConsistencyCount = promauto.NewCounter(prometheus.CounterOpts{
    98  		Name: "gossip_attestation_bad_lmd_consistency_total",
    99  		Help: "Increased when a gossip attestation has bad LMD GHOST consistency",
   100  	})
   101  	attBadSelectionProofCount = promauto.NewCounter(prometheus.CounterOpts{
   102  		Name: "gossip_attestation_bad_selection_proof_total",
   103  		Help: "Increased when a gossip attestation has a bad selection proof",
   104  	})
   105  	attBadSignatureBatchCount = promauto.NewCounter(prometheus.CounterOpts{
   106  		Name: "gossip_attestation_bad_signature_batch_total",
   107  		Help: "Increased when a gossip attestation has a bad signature batch",
   108  	})
   109  
   110  	// Attestation and block gossip verification performance.
   111  	aggregateAttestationVerificationGossipSummary = promauto.NewSummary(
   112  		prometheus.SummaryOpts{
   113  			Name: "gossip_aggregate_attestation_verification_milliseconds",
   114  			Help: "Time to verify gossiped attestations",
   115  		},
   116  	)
   117  	blockVerificationGossipSummary = promauto.NewSummary(
   118  		prometheus.SummaryOpts{
   119  			Name: "gossip_block_verification_milliseconds",
   120  			Help: "Time to verify gossiped blocks",
   121  		},
   122  	)
   123  )
   124  
   125  func (s *Service) updateMetrics() {
   126  	// do not update metrics if genesis time
   127  	// has not been initialized
   128  	if s.cfg.chain.CurrentBlock().Header().Number64().IsZero() {
   129  		return
   130  	}
   131  	// We update the dynamic subnet topics.
   132  	digest, err := s.currentForkDigest()
   133  	if err != nil {
   134  		log.Debug("Could not compute fork digest", "err", err)
   135  	}
   136  
   137  	// We update all other gossip topics.
   138  	for _, topic := range p2p.AllTopics() {
   139  		topic += s.cfg.p2p.Encoding().ProtocolSuffix()
   140  		if !strings.Contains(topic, "%x") {
   141  			topicPeerCount.WithLabelValues(topic).Set(float64(len(s.cfg.p2p.PubSub().ListPeers(topic))))
   142  			continue
   143  		}
   144  		formattedTopic := fmt.Sprintf(topic, digest)
   145  		topicPeerCount.WithLabelValues(formattedTopic).Set(float64(len(s.cfg.p2p.PubSub().ListPeers(formattedTopic))))
   146  	}
   147  
   148  	for _, topic := range s.cfg.p2p.PubSub().GetTopics() {
   149  		subscribedTopicPeerCount.WithLabelValues(topic).Set(float64(len(s.cfg.p2p.PubSub().ListPeers(topic))))
   150  	}
   151  }