github.com/grafana/pyroscope@v1.18.0/pkg/metastore/fsm/metrics.go (about)

     1  package fsm
     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  	boltDBPersistSnapshotDuration prometheus.Histogram
    13  	boltDBPersistSnapshotSize     prometheus.Gauge
    14  	boltDBRestoreSnapshotDuration prometheus.Histogram
    15  	fsmRestoreSnapshotDuration    prometheus.Histogram
    16  	fsmApplyCommandSize           *prometheus.HistogramVec
    17  	fsmApplyCommandDuration       *prometheus.HistogramVec
    18  }
    19  
    20  func newMetrics(reg prometheus.Registerer) *metrics {
    21  	var dataTimingBuckets = prometheus.ExponentialBucketsRange(0.01, 20, 48)
    22  	m := &metrics{
    23  		boltDBPersistSnapshotDuration: prometheus.NewHistogram(prometheus.HistogramOpts{
    24  			Name:                            "boltdb_persist_snapshot_duration_seconds",
    25  			Buckets:                         dataTimingBuckets,
    26  			NativeHistogramBucketFactor:     1.1,
    27  			NativeHistogramMaxBucketNumber:  100,
    28  			NativeHistogramMinResetDuration: time.Hour,
    29  		}),
    30  
    31  		boltDBPersistSnapshotSize: prometheus.NewGauge(prometheus.GaugeOpts{
    32  			Name: "boltdb_persist_snapshot_size_bytes",
    33  		}),
    34  
    35  		boltDBRestoreSnapshotDuration: prometheus.NewHistogram(prometheus.HistogramOpts{
    36  			Name:                            "boltdb_restore_snapshot_duration_seconds",
    37  			Buckets:                         dataTimingBuckets,
    38  			NativeHistogramBucketFactor:     1.1,
    39  			NativeHistogramMaxBucketNumber:  100,
    40  			NativeHistogramMinResetDuration: time.Hour,
    41  		}),
    42  
    43  		fsmRestoreSnapshotDuration: prometheus.NewHistogram(prometheus.HistogramOpts{
    44  			Name:                            "fsm_restore_snapshot_duration_seconds",
    45  			Buckets:                         dataTimingBuckets,
    46  			NativeHistogramBucketFactor:     1.1,
    47  			NativeHistogramMaxBucketNumber:  100,
    48  			NativeHistogramMinResetDuration: time.Hour,
    49  		}),
    50  
    51  		fsmApplyCommandSize: prometheus.NewHistogramVec(prometheus.HistogramOpts{
    52  			Name:                            "fsm_apply_command_size_bytes",
    53  			Buckets:                         prometheus.ExponentialBucketsRange(8, 64<<10, 48),
    54  			NativeHistogramBucketFactor:     1.1,
    55  			NativeHistogramMaxBucketNumber:  50,
    56  			NativeHistogramMinResetDuration: time.Hour,
    57  		}, []string{"command"}),
    58  
    59  		fsmApplyCommandDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{
    60  			Name:                            "fsm_apply_command_duration_seconds",
    61  			Buckets:                         dataTimingBuckets,
    62  			NativeHistogramBucketFactor:     1.1,
    63  			NativeHistogramMaxBucketNumber:  50,
    64  			NativeHistogramMinResetDuration: time.Hour,
    65  		}, []string{"command"}),
    66  	}
    67  	if reg != nil {
    68  		util.RegisterOrGet(reg, m.boltDBPersistSnapshotSize)
    69  		util.RegisterOrGet(reg, m.boltDBPersistSnapshotDuration)
    70  		util.RegisterOrGet(reg, m.boltDBRestoreSnapshotDuration)
    71  		util.RegisterOrGet(reg, m.fsmRestoreSnapshotDuration)
    72  		util.RegisterOrGet(reg, m.fsmApplyCommandSize)
    73  		util.RegisterOrGet(reg, m.fsmApplyCommandDuration)
    74  	}
    75  	return m
    76  }