Skip to content

Commit

Permalink
Merge pull request #9587 from mborsz/is_leader
Browse files Browse the repository at this point in the history
etcdserver: add is_leader prometheus metric that is 1 on the leader.
  • Loading branch information
gyuho authored Apr 19, 2018
2 parents b011208 + 46bc966 commit 8f8b32b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions etcdserver/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ var (
Name: "has_leader",
Help: "Whether or not a leader exists. 1 is existence, 0 is not.",
})
isLeader = prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "etcd",
Subsystem: "server",
Name: "is_leader",
Help: "Whether or not this member is a leader. 1 if is, 0 otherwise.",
})
leaderChanges = prometheus.NewCounter(prometheus.CounterOpts{
Namespace: "etcd",
Subsystem: "server",
Expand Down Expand Up @@ -77,6 +83,7 @@ var (

func init() {
prometheus.MustRegister(hasLeader)
prometheus.MustRegister(isLeader)
prometheus.MustRegister(leaderChanges)
prometheus.MustRegister(proposalsCommitted)
prometheus.MustRegister(proposalsApplied)
Expand Down
5 changes: 5 additions & 0 deletions etcdserver/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ func (r *raftNode) start(rh *raftReadyHandler) {

rh.updateLead(rd.SoftState.Lead)
islead = rd.RaftState == raft.StateLeader
if islead {
isLeader.Set(1)
} else {
isLeader.Set(0)
}
rh.updateLeadership(newLeader)
r.td.Reset()
}
Expand Down

0 comments on commit 8f8b32b

Please sign in to comment.