github.com/MetalBlockchain/metalgo@v1.11.9/snow/engine/snowman/metrics.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package snowman
     5  
     6  import (
     7  	"github.com/prometheus/client_golang/prometheus"
     8  
     9  	"github.com/MetalBlockchain/metalgo/utils/metric"
    10  	"github.com/MetalBlockchain/metalgo/utils/wrappers"
    11  )
    12  
    13  const (
    14  	pullGossipSource = "pull_gossip"
    15  	pushGossipSource = "push_gossip"
    16  	builtSource      = "built"
    17  	unknownSource    = "unknown"
    18  )
    19  
    20  type metrics struct {
    21  	bootstrapFinished                     prometheus.Gauge
    22  	numRequests                           prometheus.Gauge
    23  	numBlocked                            prometheus.Gauge
    24  	numBlockers                           prometheus.Gauge
    25  	numNonVerifieds                       prometheus.Gauge
    26  	numBuilt                              prometheus.Counter
    27  	numBuildsFailed                       prometheus.Counter
    28  	numUselessPutBytes                    prometheus.Counter
    29  	numUselessPushQueryBytes              prometheus.Counter
    30  	numMissingAcceptedBlocks              prometheus.Counter
    31  	numProcessingAncestorFetchesFailed    prometheus.Counter
    32  	numProcessingAncestorFetchesDropped   prometheus.Counter
    33  	numProcessingAncestorFetchesSucceeded prometheus.Counter
    34  	numProcessingAncestorFetchesUnneeded  prometheus.Counter
    35  	getAncestorsBlks                      metric.Averager
    36  	selectedVoteIndex                     metric.Averager
    37  	issuerStake                           metric.Averager
    38  	issued                                *prometheus.CounterVec
    39  }
    40  
    41  func newMetrics(reg prometheus.Registerer) (*metrics, error) {
    42  	errs := wrappers.Errs{}
    43  	m := &metrics{
    44  		bootstrapFinished: prometheus.NewGauge(prometheus.GaugeOpts{
    45  			Name: "bootstrap_finished",
    46  			Help: "Whether or not bootstrap process has completed. 1 is success, 0 is fail or ongoing.",
    47  		}),
    48  		numRequests: prometheus.NewGauge(prometheus.GaugeOpts{
    49  			Name: "requests",
    50  			Help: "Number of outstanding block requests",
    51  		}),
    52  		numBlocked: prometheus.NewGauge(prometheus.GaugeOpts{
    53  			Name: "blocked",
    54  			Help: "Number of blocks that are pending issuance",
    55  		}),
    56  		numBlockers: prometheus.NewGauge(prometheus.GaugeOpts{
    57  			Name: "blockers",
    58  			Help: "Number of blocks that are blocking other blocks from being issued because they haven't been issued",
    59  		}),
    60  		numNonVerifieds: prometheus.NewGauge(prometheus.GaugeOpts{
    61  			Name: "non_verified_blks",
    62  			Help: "Number of non-verified blocks in the memory",
    63  		}),
    64  		numBuilt: prometheus.NewCounter(prometheus.CounterOpts{
    65  			Name: "blks_built",
    66  			Help: "Number of blocks that have been built locally",
    67  		}),
    68  		numBuildsFailed: prometheus.NewCounter(prometheus.CounterOpts{
    69  			Name: "blk_builds_failed",
    70  			Help: "Number of BuildBlock calls that have failed",
    71  		}),
    72  		numUselessPutBytes: prometheus.NewCounter(prometheus.CounterOpts{
    73  			Name: "num_useless_put_bytes",
    74  			Help: "Amount of useless bytes received in Put messages",
    75  		}),
    76  		numUselessPushQueryBytes: prometheus.NewCounter(prometheus.CounterOpts{
    77  			Name: "num_useless_push_query_bytes",
    78  			Help: "Amount of useless bytes received in PushQuery messages",
    79  		}),
    80  		numMissingAcceptedBlocks: prometheus.NewCounter(prometheus.CounterOpts{
    81  			Name: "num_missing_accepted_blocks",
    82  			Help: "Number of times an accepted block height was referenced and it wasn't locally available",
    83  		}),
    84  		numProcessingAncestorFetchesFailed: prometheus.NewCounter(prometheus.CounterOpts{
    85  			Name: "num_processing_ancestor_fetches_failed",
    86  			Help: "Number of votes that were dropped due to unknown blocks",
    87  		}),
    88  		numProcessingAncestorFetchesDropped: prometheus.NewCounter(prometheus.CounterOpts{
    89  			Name: "num_processing_ancestor_fetches_dropped",
    90  			Help: "Number of votes that were dropped due to decided blocks",
    91  		}),
    92  		numProcessingAncestorFetchesSucceeded: prometheus.NewCounter(prometheus.CounterOpts{
    93  			Name: "num_processing_ancestor_fetches_succeeded",
    94  			Help: "Number of votes that were applied to ancestor blocks",
    95  		}),
    96  		numProcessingAncestorFetchesUnneeded: prometheus.NewCounter(prometheus.CounterOpts{
    97  			Name: "num_processing_ancestor_fetches_unneeded",
    98  			Help: "Number of votes that were directly applied to blocks",
    99  		}),
   100  		getAncestorsBlks: metric.NewAveragerWithErrs(
   101  			"get_ancestors_blks",
   102  			"blocks fetched in a call to GetAncestors",
   103  			reg,
   104  			&errs,
   105  		),
   106  		selectedVoteIndex: metric.NewAveragerWithErrs(
   107  			"selected_vote_index",
   108  			"index of the voteID that was passed into consensus",
   109  			reg,
   110  			&errs,
   111  		),
   112  		issuerStake: metric.NewAveragerWithErrs(
   113  			"issuer_stake",
   114  			"stake weight of the peer who provided a block that was issued into consensus",
   115  			reg,
   116  			&errs,
   117  		),
   118  		issued: prometheus.NewCounterVec(prometheus.CounterOpts{
   119  			Name: "blks_issued",
   120  			Help: "number of blocks that have been issued into consensus by discovery mechanism",
   121  		}, []string{"source"}),
   122  	}
   123  
   124  	// Register the labels
   125  	m.issued.WithLabelValues(pullGossipSource)
   126  	m.issued.WithLabelValues(pushGossipSource)
   127  	m.issued.WithLabelValues(builtSource)
   128  	m.issued.WithLabelValues(unknownSource)
   129  
   130  	errs.Add(
   131  		reg.Register(m.bootstrapFinished),
   132  		reg.Register(m.numRequests),
   133  		reg.Register(m.numBlocked),
   134  		reg.Register(m.numBlockers),
   135  		reg.Register(m.numNonVerifieds),
   136  		reg.Register(m.numBuilt),
   137  		reg.Register(m.numBuildsFailed),
   138  		reg.Register(m.numUselessPutBytes),
   139  		reg.Register(m.numUselessPushQueryBytes),
   140  		reg.Register(m.numMissingAcceptedBlocks),
   141  		reg.Register(m.numProcessingAncestorFetchesFailed),
   142  		reg.Register(m.numProcessingAncestorFetchesDropped),
   143  		reg.Register(m.numProcessingAncestorFetchesSucceeded),
   144  		reg.Register(m.numProcessingAncestorFetchesUnneeded),
   145  		reg.Register(m.issued),
   146  	)
   147  	return m, errs.Err
   148  }