Add promehteus metric about leader election status
This commit is contained in:
parent
476d0106d6
commit
7c717cabcf
4 changed files with 42 additions and 0 deletions
|
@ -269,8 +269,12 @@ func (n *NGINXController) Start() {
|
|||
if n.syncStatus != nil {
|
||||
go n.syncStatus.Run(stopCh)
|
||||
}
|
||||
|
||||
n.metricCollector.OnStartedLeading(n.cfg.ElectionID)
|
||||
},
|
||||
OnStoppedLeading: func() {
|
||||
n.metricCollector.OnStoppedLeading(n.cfg.ElectionID)
|
||||
|
||||
// Remove prometheus metrics related to SSL certificates
|
||||
srvs := sets.NewString()
|
||||
for _, s := range n.runningConfig.Servers {
|
||||
|
|
|
@ -46,6 +46,8 @@ type Controller struct {
|
|||
|
||||
constLabels prometheus.Labels
|
||||
labels prometheus.Labels
|
||||
|
||||
leaderElection *prometheus.GaugeVec
|
||||
}
|
||||
|
||||
// NewController creates a new prometheus collector for the
|
||||
|
@ -112,6 +114,13 @@ func NewController(pod, namespace, class string) *Controller {
|
|||
},
|
||||
sslLabelHost,
|
||||
),
|
||||
leaderElection: prometheus.NewGaugeVec(
|
||||
prometheus.GaugeOpts{
|
||||
Name: "leader_election_status",
|
||||
Help: "Gauge reporting status of the leader election, 0 indicates follower, 1 indicates leader. 'name' is the string used to identify the lease",
|
||||
},
|
||||
[]string{"name"},
|
||||
),
|
||||
}
|
||||
|
||||
return cm
|
||||
|
@ -127,6 +136,16 @@ func (cm *Controller) IncReloadErrorCount() {
|
|||
cm.reloadOperationErrors.With(cm.constLabels).Inc()
|
||||
}
|
||||
|
||||
// OnStartedLeading indicates the pod is not the current leader
|
||||
func (cm *Controller) OnStartedLeading(electionID string) {
|
||||
cm.leaderElection.WithLabelValues(electionID).Set(0)
|
||||
}
|
||||
|
||||
// OnStoppedLeading indicates the pod is not the current leader
|
||||
func (cm *Controller) OnStoppedLeading(electionID string) {
|
||||
cm.leaderElection.WithLabelValues(electionID).Set(1.0)
|
||||
}
|
||||
|
||||
// ConfigSuccess set a boolean flag according to the output of the controller configuration reload
|
||||
func (cm *Controller) ConfigSuccess(hash uint64, success bool) {
|
||||
if success {
|
||||
|
|
|
@ -52,3 +52,9 @@ func (dc DummyCollector) SetSSLExpireTime([]*ingress.Server) {}
|
|||
|
||||
// SetHosts ...
|
||||
func (dc DummyCollector) SetHosts(hosts sets.String) {}
|
||||
|
||||
// OnStartedLeading indicates the pod is not the current leader
|
||||
func (dc DummyCollector) OnStartedLeading(electionID string) {}
|
||||
|
||||
// OnStoppedLeading indicates the pod is not the current leader
|
||||
func (dc DummyCollector) OnStoppedLeading(electionID string) {}
|
||||
|
|
|
@ -36,6 +36,9 @@ type Collector interface {
|
|||
IncReloadCount()
|
||||
IncReloadErrorCount()
|
||||
|
||||
OnStartedLeading(string)
|
||||
OnStoppedLeading(string)
|
||||
|
||||
RemoveMetrics(ingresses, endpoints []string)
|
||||
|
||||
SetSSLExpireTime([]*ingress.Server)
|
||||
|
@ -147,3 +150,13 @@ func (c *collector) SetSSLExpireTime(servers []*ingress.Server) {
|
|||
func (c *collector) SetHosts(hosts sets.String) {
|
||||
c.socket.SetHosts(hosts)
|
||||
}
|
||||
|
||||
// OnStartedLeading indicates the pod is not the current leader
|
||||
func (c *collector) OnStartedLeading(electionID string) {
|
||||
c.ingressController.OnStartedLeading(electionID)
|
||||
}
|
||||
|
||||
// OnStoppedLeading indicates the pod is not the current leader
|
||||
func (c *collector) OnStoppedLeading(electionID string) {
|
||||
c.ingressController.OnStoppedLeading(electionID)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue