From b9d010bf780f9fbea91318b393112c9c43939a50 Mon Sep 17 00:00:00 2001 From: Tom Neuber Date: Thu, 28 Nov 2024 14:13:26 +0100 Subject: [PATCH] fix(metrics): customize bucket values & solve total request counter --- internal/exporter/metrics.go | 49 +++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/internal/exporter/metrics.go b/internal/exporter/metrics.go index 10ed73d..7df1297 100644 --- a/internal/exporter/metrics.go +++ b/internal/exporter/metrics.go @@ -28,6 +28,8 @@ type Metrics struct { metricDatabaseReady *prometheus.Desc metricRequestsTotal *prometheus.Desc metricRequestLatency *prometheus.Desc + + counter uint } func NewMetrics() *Metrics { @@ -144,13 +146,53 @@ func (m *Metrics) collectReqeustDataMetrics(ch chan<- prometheus.Metric, queue * sum float64 ) buckets := make(map[float64]uint64) - bucketBounds := prometheus.DefBuckets + bucketBounds := []float64{ + 10, + 20, + 30, + 40, + 50, + 60, + 70, + 80, + 90, + 100, + 200, + 300, + 400, + 500, + 600, + 700, + 800, + 900, + 1000, + 1500, + 2000, + 2500, + 3000, + 3500, + 4000, + 4500, + 5000, + 10000, + 20000, + 30000, + 40000, + 50000, + 100000, + 200000, + 300000, + 400000, + 500000, + 1000000, + } data := queue.ConsumeAll() for _, r := range data { - latency := r.Latency.Seconds() + latency := float64(r.Latency.Microseconds()) sum += latency count++ + log.Println(latency) for _, bound := range bucketBounds { if latency <= bound { @@ -159,10 +201,11 @@ func (m *Metrics) collectReqeustDataMetrics(ch chan<- prometheus.Metric, queue * } } + m.counter += uint(len(data)) ch <- prometheus.MustNewConstMetric( m.metricRequestsTotal, prometheus.CounterValue, - float64(len(data)), + float64(m.counter), ) ch <- prometheus.MustNewConstHistogramWithCreatedTimestamp(