Skip to content

Commit

Permalink
Merge pull request #9606 from jpbetz/automated-cherry-pick-of-#9587-r…
Browse files Browse the repository at this point in the history
…elease-3.1

Automated cherry pick of #9587
  • Loading branch information
gyuho authored Apr 23, 2018
2 parents c764878 + 3865d69 commit 5da3a72
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 @@ -28,6 +28,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 @@ -62,6 +68,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 @@ -171,6 +171,11 @@ func (r *raftNode) start(rh *raftReadyHandler) {

atomic.StoreUint64(&r.lead, rd.SoftState.Lead)
islead = rd.RaftState == raft.StateLeader
if islead {
isLeader.Set(1)
} else {
isLeader.Set(0)
}
rh.updateLeadership()
}

Expand Down

0 comments on commit 5da3a72

Please sign in to comment.