@@ -111,13 +111,25 @@ var (
111111 // PLCacheHitRatio records the hit ratio of posting list cache.
112112 PLCacheHitRatio = stats .Float64 ("hit_ratio_posting_cache" ,
113113 "Hit ratio of posting list cache" , stats .UnitDimensionless )
114+ // RaftHasLeader records whether this instance has a leader
115+ RaftHasLeader = stats .Int64 ("raft_has_leader" ,
116+ "Whether or not a leader exists for the group" , stats .UnitDimensionless )
117+ // RaftIsLeader records whether this instance is the leader
118+ RaftIsLeader = stats .Int64 ("raft_is_leader" ,
119+ "Whether or not this instance is the leader of the group" , stats .UnitDimensionless )
120+ // RaftLeaderChanges records the total number of leader changes seen.
121+ RaftLeaderChanges = stats .Int64 ("raft_leader_changes_total" ,
122+ "Total number of leader changes seen" , stats .UnitDimensionless )
114123
115124 // Conf holds the metrics config.
116125 // TODO: Request statistics, latencies, 500, timeouts
117126 Conf * expvar.Map
118127
119128 // Tag keys.
120129
130+ // KeyGroup is the tag key used to record the group for Raft metrics.
131+ KeyGroup , _ = tag .NewKey ("group" )
132+
121133 // KeyStatus is the tag key used to record the status of the server.
122134 KeyStatus , _ = tag .NewKey ("status" )
123135 // KeyMethod is the tag key used to record the method (e.g read or mutate).
@@ -141,6 +153,8 @@ var (
141153 KeyStatus , KeyMethod ,
142154 }
143155
156+ allRaftKeys = []tag.Key {KeyGroup }
157+
144158 allViews = []* view.View {
145159 {
146160 Name : LatencyMs .Name (),
@@ -163,34 +177,6 @@ var (
163177 Aggregation : view .Count (),
164178 TagKeys : allTagKeys ,
165179 },
166- {
167- Name : RaftAppliedIndex .Name (),
168- Measure : RaftAppliedIndex ,
169- Description : RaftAppliedIndex .Description (),
170- Aggregation : view .LastValue (),
171- TagKeys : allTagKeys ,
172- },
173- {
174- Name : RaftApplyCh .Name (),
175- Measure : RaftApplyCh ,
176- Description : RaftApplyCh .Description (),
177- Aggregation : view .LastValue (),
178- TagKeys : allTagKeys ,
179- },
180- {
181- Name : RaftPendingSize .Name (),
182- Measure : RaftPendingSize ,
183- Description : RaftPendingSize .Description (),
184- Aggregation : view .LastValue (),
185- TagKeys : allTagKeys ,
186- },
187- {
188- Name : MaxAssignedTs .Name (),
189- Measure : MaxAssignedTs ,
190- Description : MaxAssignedTs .Description (),
191- Aggregation : view .LastValue (),
192- TagKeys : allTagKeys ,
193- },
194180 {
195181 Name : TxnAborts .Name (),
196182 Measure : TxnAborts ,
@@ -277,6 +263,55 @@ var (
277263 Aggregation : view .LastValue (),
278264 TagKeys : allTagKeys ,
279265 },
266+ {
267+ Name : RaftAppliedIndex .Name (),
268+ Measure : RaftAppliedIndex ,
269+ Description : RaftAppliedIndex .Description (),
270+ Aggregation : view .LastValue (),
271+ TagKeys : allRaftKeys ,
272+ },
273+ {
274+ Name : RaftApplyCh .Name (),
275+ Measure : RaftApplyCh ,
276+ Description : RaftApplyCh .Description (),
277+ Aggregation : view .LastValue (),
278+ TagKeys : allRaftKeys ,
279+ },
280+ {
281+ Name : RaftPendingSize .Name (),
282+ Measure : RaftPendingSize ,
283+ Description : RaftPendingSize .Description (),
284+ Aggregation : view .LastValue (),
285+ TagKeys : allRaftKeys ,
286+ },
287+ {
288+ Name : RaftHasLeader .Name (),
289+ Measure : RaftHasLeader ,
290+ Description : RaftHasLeader .Description (),
291+ Aggregation : view .LastValue (),
292+ TagKeys : allRaftKeys ,
293+ },
294+ {
295+ Name : RaftIsLeader .Name (),
296+ Measure : RaftIsLeader ,
297+ Description : RaftIsLeader .Description (),
298+ Aggregation : view .LastValue (),
299+ TagKeys : allRaftKeys ,
300+ },
301+ {
302+ Name : RaftLeaderChanges .Name (),
303+ Measure : RaftLeaderChanges ,
304+ Description : RaftLeaderChanges .Description (),
305+ Aggregation : view .Count (),
306+ TagKeys : allRaftKeys ,
307+ },
308+ {
309+ Name : MaxAssignedTs .Name (),
310+ Measure : MaxAssignedTs ,
311+ Description : MaxAssignedTs .Description (),
312+ Aggregation : view .LastValue (),
313+ TagKeys : allTagKeys ,
314+ },
280315 }
281316)
282317
0 commit comments