github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/pkg/storage/metrics.go (about)

     1  package storage
     2  
     3  import (
     4  	"github.com/prometheus/client_golang/prometheus"
     5  	"github.com/prometheus/client_golang/prometheus/promauto"
     6  
     7  	"github.com/pyroscope-io/pyroscope/pkg/storage/cache"
     8  )
     9  
    10  type metrics struct {
    11  	putTotal prometheus.Counter
    12  	getTotal prometheus.Counter
    13  
    14  	retentionTaskDuration prometheus.Summary
    15  	evictionTaskDuration  prometheus.Summary
    16  	writeBackTaskDuration prometheus.Summary
    17  
    18  	dbSize    *prometheus.GaugeVec
    19  	cacheSize *prometheus.GaugeVec
    20  	gcCount   *prometheus.CounterVec
    21  
    22  	cacheMisses   *prometheus.CounterVec
    23  	cacheReads    *prometheus.CounterVec
    24  	cacheDBWrites *prometheus.HistogramVec
    25  	cacheDBReads  *prometheus.HistogramVec
    26  
    27  	evictionsDuration *prometheus.SummaryVec
    28  	writeBackDuration *prometheus.SummaryVec
    29  
    30  	exemplarsWriteBytes            prometheus.Summary
    31  	exemplarsReadBytes             prometheus.Summary
    32  	exemplarsRemovedTotal          prometheus.Counter
    33  	exemplarsDiscardedTotal        prometheus.Counter
    34  	exemplarsRetentionTaskDuration prometheus.Summary
    35  }
    36  
    37  func newMetrics(r prometheus.Registerer) *metrics {
    38  	name := []string{"name"}
    39  	return &metrics{
    40  		putTotal: promauto.With(r).NewCounter(prometheus.CounterOpts{
    41  			Name: "pyroscope_storage_writes_total",
    42  			Help: "number of calls to storage.Put",
    43  		}),
    44  		getTotal: promauto.With(r).NewCounter(prometheus.CounterOpts{
    45  			Name: "pyroscope_storage_reads_total",
    46  			Help: "number of calls to storage.Get",
    47  		}),
    48  
    49  		retentionTaskDuration: promauto.With(r).NewSummary(prometheus.SummaryOpts{
    50  			Name:       "pyroscope_storage_retention_task_duration_seconds",
    51  			Help:       "duration of old data deletion",
    52  			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
    53  		}),
    54  		evictionTaskDuration: promauto.With(r).NewSummary(prometheus.SummaryOpts{
    55  			Name:       "pyroscope_storage_eviction_task_duration_seconds",
    56  			Help:       "duration of evictions (triggered when there's memory pressure)",
    57  			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
    58  		}),
    59  		writeBackTaskDuration: promauto.With(r).NewSummary(prometheus.SummaryOpts{
    60  			Name:       "pyroscope_storage_writeback_task_duration_seconds",
    61  			Help:       "duration of write-back writes (triggered periodically)",
    62  			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
    63  		}),
    64  
    65  		dbSize: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{
    66  			Name: "pyroscope_storage_db_size_bytes",
    67  			Help: "size of items in disk",
    68  		}, name),
    69  		gcCount: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
    70  			Name: "pyroscope_storage_db_gc_total",
    71  			Help: "number of GC runs",
    72  		}, name),
    73  		cacheSize: promauto.With(r).NewGaugeVec(prometheus.GaugeOpts{
    74  			Name: "pyroscope_storage_db_cache_size",
    75  			Help: "number of items in cache",
    76  		}, name),
    77  
    78  		cacheDBWrites: promauto.With(r).NewHistogramVec(prometheus.HistogramOpts{
    79  			Name:    "pyroscope_storage_db_cache_write_bytes",
    80  			Help:    "bytes written to db from cache",
    81  			Buckets: prometheus.ExponentialBuckets(1024, 2, 10),
    82  		}, name),
    83  		cacheDBReads: promauto.With(r).NewHistogramVec(prometheus.HistogramOpts{
    84  			Name:    "pyroscope_storage_db_cache_read_bytes",
    85  			Help:    "bytes read from db to cache",
    86  			Buckets: prometheus.ExponentialBuckets(1024, 2, 10),
    87  		}, name),
    88  
    89  		cacheMisses: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
    90  			Name: "pyroscope_storage_db_cache_misses_total",
    91  			Help: "total number of cache misses",
    92  		}, name),
    93  		cacheReads: promauto.With(r).NewCounterVec(prometheus.CounterOpts{
    94  			Name: "pyroscope_storage_db_cache_reads_total",
    95  			Help: "total number of cache reads",
    96  		}, name),
    97  
    98  		evictionsDuration: promauto.With(r).NewSummaryVec(prometheus.SummaryOpts{
    99  			Name:       "pyroscope_storage_cache_evictions_duration_seconds",
   100  			Help:       "duration of evictions (triggered when there's memory pressure)",
   101  			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
   102  		}, name),
   103  		writeBackDuration: promauto.With(r).NewSummaryVec(prometheus.SummaryOpts{
   104  			Name:       "pyroscope_storage_cache_writeback_duration_seconds",
   105  			Help:       "duration of write-back writes (triggered periodically)",
   106  			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
   107  		}, name),
   108  
   109  		exemplarsWriteBytes: promauto.With(r).NewSummary(prometheus.SummaryOpts{
   110  			Name:       "pyroscope_storage_exemplars_write_bytes",
   111  			Help:       "bytes written to exemplars storage",
   112  			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
   113  		}),
   114  		exemplarsReadBytes: promauto.With(r).NewSummary(prometheus.SummaryOpts{
   115  			Name:       "pyroscope_storage_exemplars_read_bytes",
   116  			Help:       "bytes read from exemplars storage",
   117  			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
   118  		}),
   119  		exemplarsRemovedTotal: promauto.With(r).NewCounter(prometheus.CounterOpts{
   120  			Name: "pyroscope_storage_exemplars_removed_total",
   121  			Help: "number of exemplars removed from storage based on the retention policy",
   122  		}),
   123  		exemplarsDiscardedTotal: promauto.With(r).NewCounter(prometheus.CounterOpts{
   124  			Name: "pyroscope_storage_exemplars_discarded_total",
   125  			Help: "number of exemplars discarded",
   126  		}),
   127  		exemplarsRetentionTaskDuration: promauto.With(r).NewSummary(prometheus.SummaryOpts{
   128  			Name:       "pyroscope_storage_exemplars_retention_task_duration_seconds",
   129  			Help:       "time taken to enforce exemplars retention policy",
   130  			Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
   131  		}),
   132  	}
   133  }
   134  
   135  func (m *metrics) createCacheMetrics(name string) *cache.Metrics {
   136  	return &cache.Metrics{
   137  		MissesCounter:     m.cacheMisses.WithLabelValues(name),
   138  		ReadsCounter:      m.cacheReads.WithLabelValues(name),
   139  		DBWrites:          m.cacheDBWrites.WithLabelValues(name),
   140  		DBReads:           m.cacheDBReads.WithLabelValues(name),
   141  		EvictionsDuration: m.evictionsDuration.WithLabelValues(name),
   142  		WriteBackDuration: m.writeBackDuration.WithLabelValues(name),
   143  	}
   144  }