1
1
package metrics
2
2
3
- import "github.com/prometheus/client_golang/prometheus"
3
+ import (
4
+ "github.com/prometheus/client_golang/prometheus"
5
+ )
4
6
5
7
const (
6
8
discoveryInstanceDurations = "instance_durations"
7
9
discoveryClusterDurations = "cluster_durations"
8
10
shardCriticalLevel = "critical_level"
9
11
shardState = "state"
12
+ shardStateEvent = "shard_state_event"
13
+ )
14
+
15
+ const (
16
+ labelClusterName = "cluster_name"
17
+ labelHostName = "hostname"
18
+ labelShardState = "shard_state"
19
+ labelShardUUID = "shard_uuid"
10
20
)
11
21
12
22
var (
@@ -20,42 +30,49 @@ var (
20
30
Name : discoveryInstanceDurations ,
21
31
Help : "Instance discovery latencies in seconds" ,
22
32
Buckets : discoveryInstanceDurationsBuckets ,
23
- }, []string {"cluster_name" , "hostname" })
33
+ }, []string {labelClusterName , labelHostName })
24
34
25
35
discoveryClusterDurationsSum = prometheus .NewHistogramVec (prometheus.HistogramOpts {
26
36
Subsystem : "discovery" ,
27
37
Name : discoveryClusterDurations ,
28
38
Help : "Cluster discovery latencies in seconds" ,
29
39
Buckets : discoveryClusterDurationsBuckets ,
30
- }, []string {"cluster_name" })
40
+ }, []string {labelClusterName })
31
41
32
42
shardCriticalLevelGauge = prometheus .NewGaugeVec (prometheus.GaugeOpts {
33
43
Subsystem : "shard" ,
34
44
Name : shardCriticalLevel ,
35
45
Help : "Critical level of the replica set" ,
36
- }, []string {"cluster_name" , "uuid" , "master_uri" })
46
+ }, []string {labelClusterName , labelShardUUID })
37
47
38
48
shardStateGauge = prometheus .NewGaugeVec (prometheus.GaugeOpts {
39
49
Subsystem : "shard" ,
40
50
Name : shardState ,
41
51
Help : "The state of each shard in the cluster; it will have one line for each possible state of each shard. A value of 1 means the shard is in the state specified by the state label, a value of 0 means it is not." ,
42
- }, []string {"cluster_name" , "uuid" , "master_uri" , "state" })
52
+ }, []string {labelClusterName , labelShardUUID , labelShardState })
43
53
44
- discoveryErrors = prometheus .NewCounterVec (prometheus.CounterOpts {
54
+ discoveryErrors = prometheus .NewCounter (prometheus.CounterOpts {
45
55
Subsystem : "discovery" ,
46
56
Name : "errors" ,
47
57
Help : "Errors that happen during discovery process" ,
48
- }, []string {"cluster_name" , "uri" })
58
+ })
59
+
60
+ shardStateCounter = prometheus .NewCounterVec (prometheus.CounterOpts {
61
+ Subsystem : "orchestrator" ,
62
+ Name : shardStateEvent ,
63
+ Help : "Discovered shard state event" ,
64
+ }, []string {labelClusterName , labelShardUUID , labelShardState })
49
65
)
50
66
51
67
func init () {
52
- discoveryErrors .With (prometheus. Labels { "cluster_name" : "" , "uri" : "" }). Add (0 )
68
+ discoveryErrors .Add (0 )
53
69
prometheus .MustRegister (
54
70
discoveryInstanceDurationsSum ,
55
71
discoveryClusterDurationsSum ,
56
72
shardCriticalLevelGauge ,
57
73
shardStateGauge ,
58
74
discoveryErrors ,
75
+ shardStateCounter ,
59
76
)
60
77
}
61
78
@@ -95,26 +112,30 @@ func StartClusterDiscovery(clusterName string) Transaction {
95
112
return txn .Start ()
96
113
}
97
114
98
- func SetShardCriticalLevel (clusterName , uuid , masterURI string , level int ) {
99
- shardCriticalLevelGauge .WithLabelValues (clusterName , uuid , masterURI ).Set (float64 (level ))
115
+ func SetShardCriticalLevel (clusterName , uuid string , level int ) {
116
+ shardCriticalLevelGauge .WithLabelValues (clusterName , uuid ).Set (float64 (level ))
100
117
}
101
118
102
- func SetShardState (clusterName , uuid , masterURI , state string , active bool ) {
119
+ func SetShardState (clusterName , uuid , state string , active bool ) {
103
120
v := float64 (0 )
104
121
if active {
105
122
v = 1
106
123
}
107
124
shardStateGauge .With (prometheus.Labels {
108
- "cluster_name" : clusterName ,
109
- "uuid" : uuid ,
110
- "master_uri" : masterURI ,
111
- "state" : state ,
125
+ labelClusterName : clusterName ,
126
+ labelShardUUID : uuid ,
127
+ labelShardState : state ,
112
128
}).Set (v )
113
129
}
114
130
115
- func RecordDiscoveryError (clusterName , uri string ) {
116
- discoveryErrors .With (prometheus.Labels {
117
- "cluster_name" : clusterName ,
118
- "uri" : uri ,
131
+ func RecordDiscoveryError () {
132
+ discoveryErrors .Inc ()
133
+ }
134
+
135
+ func RecordDiscoveredShardState (clusterName , shardUUID , state string ) {
136
+ shardStateCounter .With (prometheus.Labels {
137
+ labelClusterName : clusterName ,
138
+ labelShardUUID : shardUUID ,
139
+ labelShardState : state ,
119
140
}).Inc ()
120
141
}
0 commit comments