github.com/grafana/pyroscope@v1.18.0/pkg/segmentwriter/memdb/metrics.go (about)

     1  package memdb
     2  
     3  import (
     4  	"github.com/prometheus/client_golang/prometheus"
     5  )
     6  
     7  // todo remove unused
     8  type HeadMetrics struct {
     9  	//series        prometheus.Gauge
    10  	seriesCreated *prometheus.CounterVec
    11  	//
    12  	//profiles        prometheus.Gauge
    13  	profilesCreated *prometheus.CounterVec
    14  	//
    15  	//sizeBytes   *prometheus.GaugeVec
    16  	rowsWritten *prometheus.CounterVec
    17  	//
    18  	sampleValuesIngested *prometheus.CounterVec
    19  	sampleValuesReceived *prometheus.CounterVec
    20  
    21  	flushedFileSizeBytes        *prometheus.HistogramVec
    22  	flushedBlockSizeBytes       prometheus.Histogram
    23  	flushedBlockDurationSeconds prometheus.Histogram
    24  	flushedBlockSeries          prometheus.Histogram
    25  	flushedBlockSamples         prometheus.Histogram
    26  	flusehdBlockProfiles        prometheus.Histogram
    27  	blockDurationSeconds        prometheus.Histogram
    28  	flushedBlocks               *prometheus.CounterVec
    29  	//flushedBlocksReasons        *prometheus.CounterVec
    30  	flushedBlocksUnsymbolized   *prometheus.CounterVec
    31  	writtenProfileSegments      *prometheus.CounterVec
    32  	writtenProfileSegmentsBytes prometheus.Histogram
    33  }
    34  
    35  func NewHeadMetricsWithPrefix(reg prometheus.Registerer, prefix string) *HeadMetrics {
    36  	m := &HeadMetrics{
    37  		seriesCreated: prometheus.NewCounterVec(prometheus.CounterOpts{
    38  			Name: prefix + "_tsdb_head_series_created_total",
    39  			Help: "Total number of series created in the head",
    40  		}, []string{"profile_name"}),
    41  		rowsWritten: prometheus.NewCounterVec(
    42  			prometheus.CounterOpts{
    43  				Name: prefix + "_rows_written",
    44  				Help: "Number of rows written to a parquet table.",
    45  			},
    46  			[]string{"type"}),
    47  		profilesCreated: prometheus.NewCounterVec(prometheus.CounterOpts{
    48  			Name: prefix + "_head_profiles_created_total",
    49  			Help: "Total number of profiles created in the head",
    50  		}, []string{"profile_name"}),
    51  		sampleValuesIngested: prometheus.NewCounterVec(
    52  			prometheus.CounterOpts{
    53  				Name: prefix + "_head_ingested_sample_values_total",
    54  				Help: "Number of sample values ingested into the head per profile type.",
    55  			},
    56  			[]string{"profile_name"}),
    57  		sampleValuesReceived: prometheus.NewCounterVec(
    58  			prometheus.CounterOpts{
    59  				Name: prefix + "_head_received_sample_values_total",
    60  				Help: "Number of sample values received into the head per profile type.",
    61  			},
    62  			[]string{"profile_name"}),
    63  		//sizeBytes: prometheus.NewGaugeVec(
    64  		//	prometheus.GaugeOpts{
    65  		//		Name: prefix + "_head_size_bytes",
    66  		//		Help: "Size of a particular in memory store within the head phlaredb block.",
    67  		//	},
    68  		//	[]string{"type"}),
    69  		//series: prometheus.NewGauge(prometheus.GaugeOpts{
    70  		//	Name: prefix + "_tsdb_head_series",
    71  		//	Help: "Total number of series in the head block.",
    72  		//}),
    73  		//profiles: prometheus.NewGauge(prometheus.GaugeOpts{
    74  		//	Name: prefix + "_head_profiles",
    75  		//	Help: "Total number of profiles in the head block.",
    76  		//}),
    77  		flushedFileSizeBytes: prometheus.NewHistogramVec(prometheus.HistogramOpts{
    78  			Name: prefix + "_head_flushed_table_size_bytes",
    79  			Help: "Size of a flushed table in bytes.",
    80  			//  [2MB, 4MB, 8MB, 16MB, 32MB, 64MB, 128MB, 256MB, 512MB, 1GB, 2GB]
    81  			Buckets: prometheus.ExponentialBuckets(2*1024*1024, 2, 11),
    82  		}, []string{"name"}),
    83  		flushedBlockSizeBytes: prometheus.NewHistogram(prometheus.HistogramOpts{
    84  			Name: prefix + "_head_flushed_block_size_bytes",
    85  			Help: "Size of a flushed block in bytes.",
    86  			// [50MB, 75MB, 112.5MB, 168.75MB, 253.125MB, 379.688MB, 569.532MB, 854.298MB, 1.281MB, 1.922MB, 2.883MB]
    87  			Buckets: prometheus.ExponentialBuckets(50*1024*1024, 1.5, 11),
    88  		}),
    89  		flushedBlockDurationSeconds: prometheus.NewHistogram(prometheus.HistogramOpts{
    90  			Name: prefix + "_head_flushed_block_duration_seconds",
    91  			Help: "Time to flushed a block in seconds.",
    92  			// [5s, 7.5s, 11.25s, 16.875s, 25.3125s, 37.96875s, 56.953125s, 85.4296875s, 128.14453125s, 192.216796875s]
    93  			Buckets: prometheus.ExponentialBuckets(5, 1.5, 10),
    94  		}),
    95  		flushedBlockSeries: prometheus.NewHistogram(prometheus.HistogramOpts{
    96  			Name: prefix + "_head_flushed_block_series",
    97  			Help: "Number of series in a flushed block.",
    98  			// [1k, 3k, 5k, 7k, 9k, 11k, 13k, 15k, 17k, 19k]
    99  			Buckets: prometheus.LinearBuckets(1000, 2000, 10),
   100  		}),
   101  		flushedBlockSamples: prometheus.NewHistogram(prometheus.HistogramOpts{
   102  			Name: prefix + "_head_flushed_block_samples",
   103  			Help: "Number of samples in a flushed block.",
   104  			// [200k, 400k, 800k, 1.6M, 3.2M, 6.4M, 12.8M, 25.6M, 51.2M, 102.4M, 204.8M, 409.6M, 819.2M, 1.6384G, 3.2768G]
   105  			Buckets: prometheus.ExponentialBuckets(200_000, 2, 15),
   106  		}),
   107  		flusehdBlockProfiles: prometheus.NewHistogram(prometheus.HistogramOpts{
   108  			Name: prefix + "_head_flushed_block_profiles",
   109  			Help: "Number of profiles in a flushed block.",
   110  			// [20k, 40k, 80k, 160k, 320k, 640k, 1.28M, 2.56M, 5.12M, 10.24M]
   111  			Buckets: prometheus.ExponentialBuckets(20_000, 2, 10),
   112  		}),
   113  		blockDurationSeconds: prometheus.NewHistogram(prometheus.HistogramOpts{
   114  			Name: prefix + "_head_block_duration_seconds",
   115  			Help: "Duration of a block in seconds (the range it covers).",
   116  			// [20m, 40m, 1h, 1h20, 1h40, 2h, 2h20, 2h40, 3h, 3h20, 3h40, 4h, 4h20, 4h40, 5h, 5h20, 5h40, 6h, 6h20, 6h40, 7h, 7h20, 7h40, 8h]
   117  			Buckets: prometheus.LinearBuckets(1200, 1200, 24),
   118  		}),
   119  		flushedBlocks: prometheus.NewCounterVec(prometheus.CounterOpts{
   120  			Name: prefix + "_head_flushed_blocks_total",
   121  			Help: "Total number of blocks flushed.",
   122  		}, []string{"status"}),
   123  		//flushedBlocksReasons: prometheus.NewCounterVec(prometheus.CounterOpts{
   124  		//	Name: prefix + "_head_flushed_reason_total",
   125  		//	Help: "Total count of reasons why block has been flushed.",
   126  		//}, []string{"reason"}),
   127  		flushedBlocksUnsymbolized: prometheus.NewCounterVec(prometheus.CounterOpts{
   128  			Name: prefix + "_head_flushed_blocks_unsymbolized_total",
   129  			Help: "Total number of blocks flushed, labeled by unsymbolized status (unsymbolized=true means at least one profile lacks symbols, false means all profiles are symbolized)",
   130  		}, []string{"unsymbolized"}),
   131  		writtenProfileSegments: prometheus.NewCounterVec(prometheus.CounterOpts{
   132  			Name: prefix + "_head_written_profile_segments_total",
   133  			Help: "Total number and status of profile row groups segments written.",
   134  		}, []string{"status"}),
   135  		writtenProfileSegmentsBytes: prometheus.NewHistogram(prometheus.HistogramOpts{
   136  			Name: prefix + "_head_written_profile_segments_size_bytes",
   137  			Help: "Size of a flushed table in bytes.",
   138  			//  [512KB, 1MB, 2MB, 4MB, 8MB, 16MB, 32MB, 64MB, 128MB, 256MB, 512MB]
   139  			Buckets: prometheus.ExponentialBuckets(512*1024, 2, 11),
   140  		}),
   141  		//samples: prometheus.NewGauge(prometheus.GaugeOpts{
   142  		//	Name: prefix + "_head_samples",
   143  		//	Help: "Number of samples in the head.",
   144  		//}),
   145  	}
   146  
   147  	m.register(reg)
   148  	return m
   149  }
   150  
   151  func (m *HeadMetrics) register(reg prometheus.Registerer) {
   152  	if reg == nil {
   153  		return
   154  	}
   155  	//reg.MustRegister(m.series)
   156  	reg.MustRegister(m.seriesCreated)
   157  	//reg.MustRegister(m.profiles)
   158  	reg.MustRegister(m.profilesCreated)
   159  	//reg.MustRegister(m.sizeBytes)
   160  	reg.MustRegister(m.rowsWritten)
   161  	reg.MustRegister(m.sampleValuesIngested)
   162  	reg.MustRegister(m.sampleValuesReceived)
   163  	reg.MustRegister(m.flushedFileSizeBytes)
   164  	reg.MustRegister(m.flushedBlockSizeBytes)
   165  	reg.MustRegister(m.flushedBlockDurationSeconds)
   166  	reg.MustRegister(m.flushedBlockSeries)
   167  	reg.MustRegister(m.flushedBlockSamples)
   168  	reg.MustRegister(m.flusehdBlockProfiles)
   169  	reg.MustRegister(m.blockDurationSeconds)
   170  	reg.MustRegister(m.flushedBlocks)
   171  	//reg.MustRegister(m.flushedBlocksReasons)
   172  	reg.MustRegister(m.flushedBlocksUnsymbolized)
   173  	reg.MustRegister(m.writtenProfileSegments)
   174  	reg.MustRegister(m.writtenProfileSegmentsBytes)
   175  }