From 0c96c4b157ebaca4dc1bd73b3305d18982d3d4f6 Mon Sep 17 00:00:00 2001 From: Frederic Branczyk Date: Thu, 4 May 2017 13:54:08 +0200 Subject: [PATCH] notifier: expose metric for number of discovered alertmanagers --- notifier/notifier.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/notifier/notifier.go b/notifier/notifier.go index 2f0540bbf..c293b5bc8 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -79,15 +79,16 @@ type Options struct { } type alertMetrics struct { - latency *prometheus.SummaryVec - errors *prometheus.CounterVec - sent *prometheus.CounterVec - dropped prometheus.Counter - queueLength prometheus.GaugeFunc - queueCapacity prometheus.Gauge + latency *prometheus.SummaryVec + errors *prometheus.CounterVec + sent *prometheus.CounterVec + dropped prometheus.Counter + queueLength prometheus.GaugeFunc + queueCapacity prometheus.Gauge + alertmanagersDiscovered prometheus.GaugeFunc } -func newAlertMetrics(r prometheus.Registerer, queueCap int, queueLen func() float64) *alertMetrics { +func newAlertMetrics(r prometheus.Registerer, queueCap int, queueLen, alertmanagersDiscovered func() float64) *alertMetrics { m := &alertMetrics{ latency: prometheus.NewSummaryVec(prometheus.SummaryOpts{ Namespace: namespace, @@ -131,6 +132,10 @@ func newAlertMetrics(r prometheus.Registerer, queueCap int, queueLen func() floa Name: "queue_capacity", Help: "The capacity of the alert notifications queue.", }), + alertmanagersDiscovered: prometheus.NewGaugeFunc(prometheus.GaugeOpts{ + Name: "prometheus_notifications_alertmanagers_discovered", + Help: "The number of alertmanagers discovered and active.", + }, alertmanagersDiscovered), } m.queueCapacity.Set(float64(queueCap)) @@ -143,6 +148,7 @@ func newAlertMetrics(r prometheus.Registerer, queueCap int, queueLen func() floa m.dropped, m.queueLength, m.queueCapacity, + m.alertmanagersDiscovered, ) } @@ -166,7 +172,8 @@ func New(o *Options) *Notifier { } queueLenFunc := func() float64 { return float64(n.queueLen()) } - n.metrics = newAlertMetrics(o.Registerer, o.QueueCapacity, queueLenFunc) + alertmanagersDiscoveredFunc := func() float64 { return float64(len(n.Alertmanagers())) } + n.metrics = newAlertMetrics(o.Registerer, o.QueueCapacity, queueLenFunc, alertmanagersDiscoveredFunc) return n }