forked from tair-opensource/RedisShake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
prometheus_metrics.go
95 lines (89 loc) · 2.46 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
84
85
86
87
88
89
90
91
92
93
94
95
package metric
import (
"strconv"
"redis-shake/common"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const (
metricNamespace = "redisshake"
dbSyncerLabelName = "db_syncer"
)
var (
pullCmdCountTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "pull_cmd_count_total",
Help: "RedisShake pull redis cmd count in total",
},
[]string{dbSyncerLabelName},
)
bypassCmdCountTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "bypass_cmd_count_total",
Help: "RedisShake bypass redis cmd count in total",
},
[]string{dbSyncerLabelName},
)
pushCmdCountTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "push_cmd_count_total",
Help: "RedisShake push redis cmd count in total",
},
[]string{dbSyncerLabelName},
)
successCmdCountTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "success_cmd_count_total",
Help: "RedisShake push redis cmd count in total",
},
[]string{dbSyncerLabelName},
)
failCmdCountTotal = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "fail_cmd_count_total",
Help: "RedisShake push redis cmd count in total",
},
[]string{dbSyncerLabelName},
)
networkFlowTotalInBytes = promauto.NewCounterVec(
prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "network_flow_total_in_bytes",
Help: "RedisShake total network flow in total (byte)",
},
[]string{dbSyncerLabelName},
)
fullSyncProcessPercent = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "full_sync_process_percent",
Help: "RedisShake full sync process (%)",
},
[]string{dbSyncerLabelName},
)
averageDelayInMs = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: metricNamespace,
Name: "average_delay_in_ms",
Help: "RedisShake average delay (ms)",
},
[]string{dbSyncerLabelName},
)
)
// CalcPrometheusMetrics calculates some prometheus metrics e.g. average delay.
func CalcPrometheusMetrics() {
total := utils.GetTotalLink()
for i := 0; i < total; i++ {
val, ok := MetricMap.Load(i)
if !ok {
continue
}
singleMetric := val.(*Metric)
averageDelayInMs.WithLabelValues(strconv.Itoa(i)).Set(singleMetric.GetAvgDelayFloat64())
}
}