fix(metrics): customize bucket values & solve total request counter
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/build Pipeline was successful

This commit is contained in:
Tom Neuber 2024-11-28 14:13:26 +01:00
parent 235cd4d00f
commit b9d010bf78
Signed by: tom
GPG key ID: F17EFE4272D89FF6

View file

@ -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(