github.com/grafana/pyroscope@v1.18.0/pkg/distributor/metrics.go (about) 1 package distributor 2 3 import ( 4 "fmt" 5 6 "github.com/prometheus/client_golang/prometheus" 7 ) 8 9 const ( 10 minBytes = 10 * 1024 11 maxBytes = 15 * 1024 * 1024 12 bucketsCount = 30 13 ) 14 15 type ReceiveStage string 16 17 const ( 18 // StageReceived is the earliest stage and as soon as we begin processing a profile, 19 // before any rate-limit/sampling checks 20 StageReceived ReceiveStage = "received" 21 // StageSampled is recorded after the profile is accepted by rate-limit/sampling checks 22 StageSampled ReceiveStage = "sampled" 23 // StageNormalized is recorded after the profile is validated and normalized. 24 StageNormalized ReceiveStage = "normalized" 25 ) 26 27 var allStages = fmt.Sprintf("%s, %s, %s", 28 StageReceived, 29 StageSampled, 30 StageNormalized, 31 ) 32 33 type metrics struct { 34 receivedCompressedBytes *prometheus.HistogramVec 35 receivedDecompressedBytes *prometheus.HistogramVec // deprecated TODO remove 36 receivedSamples *prometheus.HistogramVec 37 receivedSamplesBytes *prometheus.HistogramVec 38 receivedSymbolsBytes *prometheus.HistogramVec 39 replicationFactor prometheus.Gauge 40 receivedDecompressedBytesTotal *prometheus.HistogramVec 41 } 42 43 func newMetrics(reg prometheus.Registerer) *metrics { 44 m := &metrics{ 45 replicationFactor: prometheus.NewGauge(prometheus.GaugeOpts{ 46 Namespace: "pyroscope", 47 Name: "distributor_replication_factor", 48 Help: "The configured replication factor for the distributor.", 49 }), 50 receivedCompressedBytes: prometheus.NewHistogramVec( 51 prometheus.HistogramOpts{ 52 Namespace: "pyroscope", 53 Name: "distributor_received_compressed_bytes", 54 Help: "The number of compressed bytes per profile received by the distributor.", 55 Buckets: prometheus.ExponentialBucketsRange(minBytes, maxBytes, bucketsCount), 56 }, 57 []string{"type", "tenant"}, 58 ), 59 receivedDecompressedBytes: prometheus.NewHistogramVec( 60 prometheus.HistogramOpts{ 61 Namespace: "pyroscope", 62 Name: "distributor_received_decompressed_bytes", 63 Help: "The number of decompressed bytes per profiles received by the distributor after " + 64 "limits/sampling checks. distributor_received_decompressed_bytes is deprecated, use " + 65 "distributor_received_decompressed_bytes_total instead.", 66 Buckets: prometheus.ExponentialBucketsRange(minBytes, maxBytes, bucketsCount), 67 }, 68 []string{"type", "tenant"}, 69 ), 70 receivedSamples: prometheus.NewHistogramVec( 71 prometheus.HistogramOpts{ 72 Namespace: "pyroscope", 73 Name: "distributor_received_samples", 74 Help: "The number of samples per profile name received by the distributor.", 75 Buckets: prometheus.ExponentialBucketsRange(100, 100000, 30), 76 }, 77 []string{"type", "tenant"}, 78 ), 79 receivedSamplesBytes: prometheus.NewHistogramVec( 80 prometheus.HistogramOpts{ 81 Namespace: "pyroscope", 82 Name: "distributor_received_samples_bytes", 83 Help: "The size of samples without symbols received by the distributor.", 84 Buckets: prometheus.ExponentialBucketsRange(10*1024, 15*1024*1024, 30), 85 }, 86 []string{"type", "tenant"}, 87 ), 88 receivedSymbolsBytes: prometheus.NewHistogramVec( 89 prometheus.HistogramOpts{ 90 Namespace: "pyroscope", 91 Name: "distributor_received_symbols_bytes", 92 Help: "The size of symbols received by the distributor.", 93 Buckets: prometheus.ExponentialBucketsRange(10*1024, 15*1024*1024, 30), 94 }, 95 []string{"type", "tenant"}, 96 ), 97 receivedDecompressedBytesTotal: prometheus.NewHistogramVec( 98 prometheus.HistogramOpts{ 99 Namespace: "pyroscope", 100 Name: "distributor_received_decompressed_bytes_total", 101 Help: "The total number of decompressed bytes per profile received by the distributor at different " + 102 "processing stages. Valid stages are: " + allStages, 103 Buckets: prometheus.ExponentialBucketsRange(minBytes, maxBytes, bucketsCount), 104 }, 105 []string{ 106 "tenant", 107 "stage", 108 }, 109 ), 110 } 111 if reg != nil { 112 reg.MustRegister( 113 m.receivedCompressedBytes, 114 m.receivedDecompressedBytes, 115 m.receivedSamples, 116 m.receivedSamplesBytes, 117 m.receivedSymbolsBytes, 118 m.replicationFactor, 119 m.receivedDecompressedBytesTotal, 120 ) 121 } 122 return m 123 } 124 125 func (m *metrics) observeProfileSize(tenant string, stage ReceiveStage, sz int64) { 126 m.receivedDecompressedBytesTotal.WithLabelValues(tenant, string(stage)).Observe(float64(sz)) 127 }