Merge pull request #2678 from brancz/am-discovery-metrics

notifier: expose metric for number of discovered alertmanagers
pull/2562/merge
Fabian Reinartz 8 years ago committed by GitHub
commit a333c5612a

@ -79,15 +79,16 @@ type Options struct {
} }
type alertMetrics struct { type alertMetrics struct {
latency *prometheus.SummaryVec latency *prometheus.SummaryVec
errors *prometheus.CounterVec errors *prometheus.CounterVec
sent *prometheus.CounterVec sent *prometheus.CounterVec
dropped prometheus.Counter dropped prometheus.Counter
queueLength prometheus.GaugeFunc queueLength prometheus.GaugeFunc
queueCapacity prometheus.Gauge 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{ m := &alertMetrics{
latency: prometheus.NewSummaryVec(prometheus.SummaryOpts{ latency: prometheus.NewSummaryVec(prometheus.SummaryOpts{
Namespace: namespace, Namespace: namespace,
@ -131,6 +132,10 @@ func newAlertMetrics(r prometheus.Registerer, queueCap int, queueLen func() floa
Name: "queue_capacity", Name: "queue_capacity",
Help: "The capacity of the alert notifications queue.", 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)) m.queueCapacity.Set(float64(queueCap))
@ -143,6 +148,7 @@ func newAlertMetrics(r prometheus.Registerer, queueCap int, queueLen func() floa
m.dropped, m.dropped,
m.queueLength, m.queueLength,
m.queueCapacity, m.queueCapacity,
m.alertmanagersDiscovered,
) )
} }
@ -166,7 +172,8 @@ func New(o *Options) *Notifier {
} }
queueLenFunc := func() float64 { return float64(n.queueLen()) } 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 return n
} }

Loading…
Cancel
Save