github.com/grafana/pyroscope@v1.18.0/pkg/metastore/raftnode/node_metrics.go (about)

     1  package raftnode
     2  
     3  import (
     4  	"time"
     5  
     6  	"github.com/prometheus/client_golang/prometheus"
     7  
     8  	"github.com/grafana/pyroscope/pkg/util"
     9  )
    10  
    11  type metrics struct {
    12  	apply prometheus.Histogram
    13  	read  prometheus.Histogram
    14  	state *prometheus.GaugeVec
    15  }
    16  
    17  func newMetrics(reg prometheus.Registerer) *metrics {
    18  	m := &metrics{
    19  		apply: prometheus.NewHistogram(prometheus.HistogramOpts{
    20  			Name:                            "raft_apply_command_duration_seconds",
    21  			Help:                            "Duration of applying a command to the Raft log",
    22  			Buckets:                         prometheus.DefBuckets,
    23  			NativeHistogramBucketFactor:     1.1,
    24  			NativeHistogramZeroThreshold:    0,
    25  			NativeHistogramMaxBucketNumber:  50,
    26  			NativeHistogramMinResetDuration: time.Hour,
    27  			NativeHistogramMaxZeroThreshold: 0,
    28  		}),
    29  
    30  		read: prometheus.NewHistogram(prometheus.HistogramOpts{
    31  			Name:                            "raft_read_index_wait_duration_seconds",
    32  			Help:                            "Duration of the Raft log read index wait",
    33  			Buckets:                         prometheus.DefBuckets,
    34  			NativeHistogramBucketFactor:     1.1,
    35  			NativeHistogramZeroThreshold:    0,
    36  			NativeHistogramMaxBucketNumber:  50,
    37  			NativeHistogramMinResetDuration: time.Hour,
    38  			NativeHistogramMaxZeroThreshold: 0,
    39  		}),
    40  
    41  		state: prometheus.NewGaugeVec(
    42  			prometheus.GaugeOpts{
    43  				Name: "raft_state",
    44  				Help: "Current Raft state",
    45  			},
    46  			[]string{"state"},
    47  		),
    48  	}
    49  
    50  	if reg != nil {
    51  		util.RegisterOrGet(reg, m.apply)
    52  		util.RegisterOrGet(reg, m.read)
    53  		util.RegisterOrGet(reg, m.state)
    54  	}
    55  
    56  	return m
    57  }