grafana/pkg/services/ngalert/metrics/alertmanager.go
Santiago 3afd94185c
Alerting: Add metric to check for default AM configurations (#80225)
* Alerting: Add metric to check for default AM configurations

* Use a gauge for the config hash

* don't go out of bounds when converting uint64 to float64

* expose metric for config hash

* update metrics after applying config
2024-01-16 17:12:24 +01:00

62 lines
1.8 KiB
Go

package metrics
import (
"fmt"
"github.com/prometheus/alertmanager/api/metrics"
"github.com/prometheus/client_golang/prometheus"
)
type Alertmanager struct {
Registerer prometheus.Registerer
*metrics.Alerts
*AlertmanagerConfigMetrics
}
// NewAlertmanagerMetrics creates a set of metrics for the Alertmanager of each organization.
func NewAlertmanagerMetrics(r prometheus.Registerer) *Alertmanager {
other := prometheus.WrapRegistererWithPrefix(fmt.Sprintf("%s_%s_", Namespace, Subsystem), r)
return &Alertmanager{
Registerer: r,
Alerts: metrics.NewAlerts("grafana", other),
AlertmanagerConfigMetrics: NewAlertmanagerConfigMetrics(r),
}
}
type AlertmanagerConfigMetrics struct {
ConfigHash *prometheus.GaugeVec
Matchers prometheus.Gauge
MatchRE prometheus.Gauge
Match prometheus.Gauge
ObjectMatchers prometheus.Gauge
}
func NewAlertmanagerConfigMetrics(r prometheus.Registerer) *AlertmanagerConfigMetrics {
m := &AlertmanagerConfigMetrics{
ConfigHash: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "alertmanager_config_hash",
Help: "The hash of the Alertmanager configuration.",
}, []string{"org"}),
Matchers: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "alertmanager_config_matchers",
Help: "The total number of matchers",
}),
MatchRE: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "alertmanager_config_match_re",
Help: "The total number of matche_re",
}),
Match: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "alertmanager_config_match",
Help: "The total number of match",
}),
ObjectMatchers: prometheus.NewGauge(prometheus.GaugeOpts{
Name: "alertmanager_config_object_matchers",
Help: "The total number of object_matchers",
}),
}
if r != nil {
r.MustRegister(m.ConfigHash, m.Matchers, m.MatchRE, m.Match, m.ObjectMatchers)
}
return m
}