mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
etcdserver: add is_leader prometheus metric that is 1 on the leader.
Before this change, we had now way to find a leader using /metrics endpoint. This commit adds a metric to do that.
This commit is contained in:
parent
16487395e1
commit
3865d69db3
@ -28,6 +28,12 @@ var (
|
|||||||
Name: "has_leader",
|
Name: "has_leader",
|
||||||
Help: "Whether or not a leader exists. 1 is existence, 0 is not.",
|
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{
|
leaderChanges = prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
Namespace: "etcd",
|
Namespace: "etcd",
|
||||||
Subsystem: "server",
|
Subsystem: "server",
|
||||||
@ -62,6 +68,7 @@ var (
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
prometheus.MustRegister(hasLeader)
|
prometheus.MustRegister(hasLeader)
|
||||||
|
prometheus.MustRegister(isLeader)
|
||||||
prometheus.MustRegister(leaderChanges)
|
prometheus.MustRegister(leaderChanges)
|
||||||
prometheus.MustRegister(proposalsCommitted)
|
prometheus.MustRegister(proposalsCommitted)
|
||||||
prometheus.MustRegister(proposalsApplied)
|
prometheus.MustRegister(proposalsApplied)
|
||||||
|
@ -171,6 +171,11 @@ func (r *raftNode) start(rh *raftReadyHandler) {
|
|||||||
|
|
||||||
atomic.StoreUint64(&r.lead, rd.SoftState.Lead)
|
atomic.StoreUint64(&r.lead, rd.SoftState.Lead)
|
||||||
islead = rd.RaftState == raft.StateLeader
|
islead = rd.RaftState == raft.StateLeader
|
||||||
|
if islead {
|
||||||
|
isLeader.Set(1)
|
||||||
|
} else {
|
||||||
|
isLeader.Set(0)
|
||||||
|
}
|
||||||
rh.updateLeadership()
|
rh.updateLeadership()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user