-
Notifications
You must be signed in to change notification settings - Fork 0
/
prometheus_metrics.go
83 lines (78 loc) · 2.43 KB
/
prometheus_metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* // Copyright 2020 Insolar Network Ltd.
* // All rights reserved.
* // This material is licensed under the Insolar License version 1.0,
* // available at https://github.com/insolar/assured-ledger/blob/master/LICENSE.md.
*/
package loaderbot
import (
"github.com/prometheus/client_golang/prometheus"
)
type PromReporter struct {
promTickSuccessRatio prometheus.Gauge
promTickP50 prometheus.Gauge
promTickP95 prometheus.Gauge
promTickP99 prometheus.Gauge
promTickMax prometheus.Gauge
promRPS prometheus.Gauge
}
func NewPromReporter(label string) *PromReporter {
m := &PromReporter{}
m.promTickSuccessRatio = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "loaderbot_tick_success_ratio",
Help: "Success requests ratio",
ConstLabels: prometheus.Labels{
"runner_name": label,
},
})
_ = prometheus.Register(m.promTickSuccessRatio)
m.promTickP50 = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "loaderbot_tick_p50",
Help: "Response time 50 Percentile",
ConstLabels: prometheus.Labels{
"runner_name": label,
},
})
_ = prometheus.Register(m.promTickP50)
m.promTickP95 = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "loaderbot_tick_p95",
Help: "Response time 95 Percentile",
ConstLabels: prometheus.Labels{
"runner_name": label,
},
})
_ = prometheus.Register(m.promTickP95)
m.promTickP99 = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "loaderbot_tick_p99",
Help: "Response time 99 Percentile",
ConstLabels: prometheus.Labels{
"runner_name": label,
},
})
_ = prometheus.Register(m.promTickP99)
m.promTickMax = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "loaderbot_tick_max",
Help: "Response time MAX",
ConstLabels: prometheus.Labels{
"runner_name": label,
},
})
_ = prometheus.Register(m.promTickMax)
m.promRPS = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "loaderbot_tick_rps",
Help: "Requests per second rate",
ConstLabels: prometheus.Labels{
"runner_name": label,
},
})
_ = prometheus.Register(m.promRPS)
return m
}
func (m *PromReporter) reportTick(tm *TickMetrics) {
m.promTickP50.Set(float64(tm.Metrics.Latencies.P50.Milliseconds()))
m.promTickP95.Set(float64(tm.Metrics.Latencies.P95.Milliseconds()))
m.promTickP99.Set(float64(tm.Metrics.Latencies.P99.Milliseconds()))
m.promTickMax.Set(float64(tm.Metrics.Latencies.Max.Milliseconds()))
m.promTickSuccessRatio.Set(tm.Metrics.Success)
m.promRPS.Set(tm.Metrics.Rate)
}