|
| 1 | +package symbolizer |
| 2 | + |
| 3 | +import "github.com/prometheus/client_golang/prometheus" |
| 4 | + |
| 5 | +type Metrics struct { |
| 6 | + registerer prometheus.Registerer |
| 7 | + |
| 8 | + // Debuginfod metrics |
| 9 | + debuginfodRequestDuration *prometheus.HistogramVec |
| 10 | + debuginfodFileSize prometheus.Histogram |
| 11 | + debuginfodRequestsTotal prometheus.Counter |
| 12 | + debuginfodRequestErrorsTotal *prometheus.CounterVec |
| 13 | + |
| 14 | + // Cache metrics |
| 15 | + cacheRequestsTotal *prometheus.CounterVec |
| 16 | + cacheRequestErrorsTotal *prometheus.CounterVec |
| 17 | + cacheHitsTotal prometheus.Counter |
| 18 | + cacheMissesTotal prometheus.Counter |
| 19 | + cacheOperationDuration *prometheus.HistogramVec |
| 20 | + cacheExpiredTotal prometheus.Counter |
| 21 | + |
| 22 | + // Symbolization metrics |
| 23 | + //symbolizationDuration prometheus.Histogram |
| 24 | + //symbolizationLocations *prometheus.CounterVec |
| 25 | + symbolizationRequestsTotal prometheus.Counter |
| 26 | + symbolizationRequestErrorsTotal *prometheus.CounterVec |
| 27 | + symbolizationDuration prometheus.Histogram |
| 28 | + symbolizationLocationTotal *prometheus.CounterVec |
| 29 | +} |
| 30 | + |
| 31 | +func NewMetrics(reg prometheus.Registerer) *Metrics { |
| 32 | + m := &Metrics{ |
| 33 | + registerer: reg, |
| 34 | + debuginfodRequestDuration: prometheus.NewHistogramVec(prometheus.HistogramOpts{ |
| 35 | + Name: "pyroscope_symbolizer_debuginfod_request_duration_seconds", |
| 36 | + Help: "Time spent performing debuginfod requests", |
| 37 | + Buckets: []float64{0.1, 0.5, 1, 5, 10, 30, 60, 120, 300}, |
| 38 | + }, []string{"status"}, |
| 39 | + ), |
| 40 | + debuginfodFileSize: prometheus.NewHistogram( |
| 41 | + prometheus.HistogramOpts{ |
| 42 | + Name: "pyroscope_symbolizer_debuginfo_file_size_bytes", |
| 43 | + Help: "Size of debug info files fetched from debuginfod", |
| 44 | + // 1MB to 4GB |
| 45 | + Buckets: prometheus.ExponentialBuckets(1024*1024, 2, 12), |
| 46 | + }, |
| 47 | + ), |
| 48 | + debuginfodRequestsTotal: prometheus.NewCounter(prometheus.CounterOpts{ |
| 49 | + Name: "pyroscope_symbolizer_debuginfod_requests_total", |
| 50 | + Help: "Total number of debuginfod requests attempted", |
| 51 | + }), |
| 52 | + debuginfodRequestErrorsTotal: prometheus.NewCounterVec(prometheus.CounterOpts{ |
| 53 | + Name: "pyroscope_symbolizer_debuginfod_request_errors_total", |
| 54 | + Help: "Total number of debuginfod request errors", |
| 55 | + }, []string{"reason"}), |
| 56 | + cacheRequestsTotal: prometheus.NewCounterVec(prometheus.CounterOpts{ |
| 57 | + Name: "pyroscope_symbolizer_cache_requests_total", |
| 58 | + Help: "Total number of cache requests", |
| 59 | + }, []string{"operation"}), |
| 60 | + cacheRequestErrorsTotal: prometheus.NewCounterVec(prometheus.CounterOpts{ |
| 61 | + Name: "pyroscope_symbolizer_cache_request_errors_total", |
| 62 | + Help: "Total number of cache request errors", |
| 63 | + }, []string{"operation", "reason"}), // get/put, and specific error reasons |
| 64 | + cacheHitsTotal: prometheus.NewCounter(prometheus.CounterOpts{ |
| 65 | + Name: "pyroscope_symbolizer_cache_hits_total", |
| 66 | + Help: "Total number of cache hits", |
| 67 | + }), |
| 68 | + cacheMissesTotal: prometheus.NewCounter(prometheus.CounterOpts{ |
| 69 | + Name: "pyroscope_symbolizer_cache_misses_total", |
| 70 | + Help: "Total number of cache misses", |
| 71 | + }), |
| 72 | + cacheOperationDuration: prometheus.NewHistogramVec( |
| 73 | + prometheus.HistogramOpts{ |
| 74 | + Name: "pyroscope_symbolizer_cache_operation_duration_seconds", |
| 75 | + Help: "Time spent performing cache operations", |
| 76 | + Buckets: []float64{.01, .05, .1, .5, 1, 5, 10, 30, 60}, |
| 77 | + }, |
| 78 | + []string{"operation"}, |
| 79 | + ), |
| 80 | + cacheExpiredTotal: prometheus.NewCounter(prometheus.CounterOpts{ |
| 81 | + Name: "pyroscope_symbolizer_cache_expired_total", |
| 82 | + Help: "Total number of expired items removed from cache", |
| 83 | + }), |
| 84 | + symbolizationRequestsTotal: prometheus.NewCounter(prometheus.CounterOpts{ |
| 85 | + Name: "pyroscope_symbolizer_requests_total", |
| 86 | + Help: "Total number of symbolization requests", |
| 87 | + }), |
| 88 | + symbolizationRequestErrorsTotal: prometheus.NewCounterVec(prometheus.CounterOpts{ |
| 89 | + Name: "pyroscope_symbolizer_request_errors_total", |
| 90 | + Help: "Total number of symbolization errors", |
| 91 | + }, []string{"reason"}), |
| 92 | + symbolizationDuration: prometheus.NewHistogram( |
| 93 | + prometheus.HistogramOpts{ |
| 94 | + Name: "pyroscope_symbolizer_duration_seconds", |
| 95 | + Help: "Time spent performing symbolization", |
| 96 | + Buckets: []float64{.01, .05, .1, .5, 1, 5, 10, 30}, |
| 97 | + }, |
| 98 | + ), |
| 99 | + symbolizationLocationTotal: prometheus.NewCounterVec(prometheus.CounterOpts{ |
| 100 | + Name: "pyroscope_symbolizer_locations_total", |
| 101 | + Help: "Total number of locations processed", |
| 102 | + }, []string{"status"}), |
| 103 | + } |
| 104 | + m.register() |
| 105 | + return m |
| 106 | +} |
| 107 | + |
| 108 | +func (m *Metrics) register() { |
| 109 | + if m.registerer == nil { |
| 110 | + return |
| 111 | + } |
| 112 | + |
| 113 | + collectors := []prometheus.Collector{ |
| 114 | + m.debuginfodRequestDuration, |
| 115 | + m.debuginfodFileSize, |
| 116 | + m.debuginfodRequestErrorsTotal, |
| 117 | + m.debuginfodRequestsTotal, |
| 118 | + m.cacheRequestsTotal, |
| 119 | + m.cacheRequestErrorsTotal, |
| 120 | + m.cacheHitsTotal, |
| 121 | + m.cacheMissesTotal, |
| 122 | + m.cacheOperationDuration, |
| 123 | + m.cacheExpiredTotal, |
| 124 | + m.symbolizationRequestsTotal, |
| 125 | + m.symbolizationRequestErrorsTotal, |
| 126 | + m.symbolizationDuration, |
| 127 | + m.symbolizationLocationTotal, |
| 128 | + } |
| 129 | + |
| 130 | + for _, collector := range collectors { |
| 131 | + m.registerer.MustRegister(collector) |
| 132 | + } |
| 133 | +} |
| 134 | + |
| 135 | +func (m *Metrics) Unregister() { |
| 136 | + if m.registerer == nil { |
| 137 | + return |
| 138 | + } |
| 139 | + |
| 140 | + collectors := []prometheus.Collector{ |
| 141 | + m.debuginfodRequestDuration, |
| 142 | + m.debuginfodFileSize, |
| 143 | + m.debuginfodRequestErrorsTotal, |
| 144 | + m.debuginfodRequestsTotal, |
| 145 | + m.cacheRequestsTotal, |
| 146 | + m.cacheRequestErrorsTotal, |
| 147 | + m.cacheHitsTotal, |
| 148 | + m.cacheMissesTotal, |
| 149 | + m.cacheOperationDuration, |
| 150 | + m.cacheExpiredTotal, |
| 151 | + m.symbolizationRequestsTotal, |
| 152 | + m.symbolizationRequestErrorsTotal, |
| 153 | + m.symbolizationDuration, |
| 154 | + m.symbolizationLocationTotal, |
| 155 | + } |
| 156 | + |
| 157 | + for _, collector := range collectors { |
| 158 | + m.registerer.Unregister(collector) |
| 159 | + } |
| 160 | +} |
0 commit comments