fix(metrics): customize bucket values & solve total request counter
This commit is contained in:
parent
235cd4d00f
commit
b9d010bf78
1 changed files with 46 additions and 3 deletions
|
@ -28,6 +28,8 @@ type Metrics struct {
|
||||||
metricDatabaseReady *prometheus.Desc
|
metricDatabaseReady *prometheus.Desc
|
||||||
metricRequestsTotal *prometheus.Desc
|
metricRequestsTotal *prometheus.Desc
|
||||||
metricRequestLatency *prometheus.Desc
|
metricRequestLatency *prometheus.Desc
|
||||||
|
|
||||||
|
counter uint
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMetrics() *Metrics {
|
func NewMetrics() *Metrics {
|
||||||
|
@ -144,13 +146,53 @@ func (m *Metrics) collectReqeustDataMetrics(ch chan<- prometheus.Metric, queue *
|
||||||
sum float64
|
sum float64
|
||||||
)
|
)
|
||||||
buckets := make(map[float64]uint64)
|
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()
|
data := queue.ConsumeAll()
|
||||||
for _, r := range data {
|
for _, r := range data {
|
||||||
latency := r.Latency.Seconds()
|
latency := float64(r.Latency.Microseconds())
|
||||||
sum += latency
|
sum += latency
|
||||||
count++
|
count++
|
||||||
|
log.Println(latency)
|
||||||
|
|
||||||
for _, bound := range bucketBounds {
|
for _, bound := range bucketBounds {
|
||||||
if latency <= bound {
|
if latency <= bound {
|
||||||
|
@ -159,10 +201,11 @@ func (m *Metrics) collectReqeustDataMetrics(ch chan<- prometheus.Metric, queue *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.counter += uint(len(data))
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
m.metricRequestsTotal,
|
m.metricRequestsTotal,
|
||||||
prometheus.CounterValue,
|
prometheus.CounterValue,
|
||||||
float64(len(data)),
|
float64(m.counter),
|
||||||
)
|
)
|
||||||
|
|
||||||
ch <- prometheus.MustNewConstHistogramWithCreatedTimestamp(
|
ch <- prometheus.MustNewConstHistogramWithCreatedTimestamp(
|
||||||
|
|
Loading…
Reference in a new issue