github.com/vipernet-xyz/tendermint-core@v0.32.0/state/metrics.go (about)

     1  package state
     2  
     3  import (
     4  	"github.com/go-kit/kit/metrics"
     5  	"github.com/go-kit/kit/metrics/discard"
     6  	"github.com/go-kit/kit/metrics/prometheus"
     7  	stdprometheus "github.com/prometheus/client_golang/prometheus"
     8  )
     9  
    10  const (
    11  	// MetricsSubsystem is a subsystem shared by all metrics exposed by this
    12  	// package.
    13  	MetricsSubsystem = "state"
    14  )
    15  
    16  // Metrics contains metrics exposed by this package.
    17  type Metrics struct {
    18  	// Time between BeginBlock and EndBlock.
    19  	BlockProcessingTime metrics.Histogram
    20  }
    21  
    22  // PrometheusMetrics returns Metrics build using Prometheus client library.
    23  // Optionally, labels can be provided along with their values ("foo",
    24  // "fooValue").
    25  func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
    26  	labels := []string{}
    27  	for i := 0; i < len(labelsAndValues); i += 2 {
    28  		labels = append(labels, labelsAndValues[i])
    29  	}
    30  	return &Metrics{
    31  		BlockProcessingTime: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
    32  			Namespace: namespace,
    33  			Subsystem: MetricsSubsystem,
    34  			Name:      "block_processing_time",
    35  			Help:      "Time between BeginBlock and EndBlock in ms.",
    36  			Buckets:   stdprometheus.LinearBuckets(1, 10, 10),
    37  		}, labels).With(labelsAndValues...),
    38  	}
    39  }
    40  
    41  // NopMetrics returns no-op Metrics.
    42  func NopMetrics() *Metrics {
    43  	return &Metrics{
    44  		BlockProcessingTime: discard.NewHistogram(),
    45  	}
    46  }