github.com/PikeEcosystem/tendermint@v0.0.4/mempool/metrics.go (about)

     1  package mempool
     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 = "mempool"
    14  )
    15  
    16  // Metrics contains metrics exposed by this package.
    17  // see MetricsProvider for descriptions.
    18  type Metrics struct {
    19  	// Size of the mempool.
    20  	Size metrics.Gauge
    21  	// Histogram of transaction sizes, in bytes.
    22  	TxSizeBytes metrics.Histogram
    23  	// Number of failed transactions.
    24  	FailedTxs metrics.Counter
    25  	// Number of times transactions are rechecked in the mempool.
    26  	RecheckCount metrics.Counter
    27  	// Time of recheck transactions in the mempool.
    28  	RecheckTime metrics.Gauge
    29  }
    30  
    31  // PrometheusMetrics returns Metrics build using Prometheus client library.
    32  // Optionally, labels can be provided along with their values ("foo",
    33  // "fooValue").
    34  func PrometheusMetrics(namespace string, labelsAndValues ...string) *Metrics {
    35  	labels := []string{}
    36  	for i := 0; i < len(labelsAndValues); i += 2 {
    37  		labels = append(labels, labelsAndValues[i])
    38  	}
    39  	return &Metrics{
    40  		Size: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
    41  			Namespace: namespace,
    42  			Subsystem: MetricsSubsystem,
    43  			Name:      "size",
    44  			Help:      "Size of the mempool (number of uncommitted transactions).",
    45  		}, labels).With(labelsAndValues...),
    46  		TxSizeBytes: prometheus.NewHistogramFrom(stdprometheus.HistogramOpts{
    47  			Namespace: namespace,
    48  			Subsystem: MetricsSubsystem,
    49  			Name:      "tx_size_bytes",
    50  			Help:      "Transaction sizes in bytes.",
    51  			Buckets:   stdprometheus.ExponentialBuckets(1, 3, 17),
    52  		}, labels).With(labelsAndValues...),
    53  		FailedTxs: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
    54  			Namespace: namespace,
    55  			Subsystem: MetricsSubsystem,
    56  			Name:      "failed_txs",
    57  			Help:      "Number of failed transactions.",
    58  		}, labels).With(labelsAndValues...),
    59  		RecheckCount: prometheus.NewCounterFrom(stdprometheus.CounterOpts{
    60  			Namespace: namespace,
    61  			Subsystem: MetricsSubsystem,
    62  			Name:      "recheck_count",
    63  			Help:      "Number of times transactions are rechecked in the mempool.",
    64  		}, labels).With(labelsAndValues...),
    65  		RecheckTime: prometheus.NewGaugeFrom(stdprometheus.GaugeOpts{
    66  			Namespace: namespace,
    67  			Subsystem: MetricsSubsystem,
    68  			Name:      "recheck_time",
    69  			Help:      "Time of recheck transactions in the mempool in ms.",
    70  		}, labels).With(labelsAndValues...),
    71  	}
    72  }
    73  
    74  // NopMetrics returns no-op Metrics.
    75  func NopMetrics() *Metrics {
    76  	return &Metrics{
    77  		Size:         discard.NewGauge(),
    78  		TxSizeBytes:  discard.NewHistogram(),
    79  		FailedTxs:    discard.NewCounter(),
    80  		RecheckCount: discard.NewCounter(),
    81  		RecheckTime:  discard.NewGauge(),
    82  	}
    83  }