mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
c8ccc4649c
This pull request updates our fork of Alertmanager to commit 65bdab0, which is based on commit 5658f8c in Prometheus Alertmanager. It applies the changes from grafana/alerting#155 which removes the overrides for validation of alerts, labels and silences that we had put in place to allow alerts and silences to work for non-Prometheus datasources. However, as this is now supported in Alertmanager with the UTF-8 work, we can use the new upstream functions and remove these overrides. The compat package is a package in Alertmanager that takes care of backwards compatibility when parsing matchers, validating alerts, labels and silences. It has three modes: classic mode, UTF-8 strict mode, fallback mode. These modes are controlled via compat.InitFromFlags. Grafana initializes the compat package without any feature flags, which is the equivalent of fallback mode. Classic and UTF-8 strict mode are used in Mimir. While Grafana Managed Alerts have no need for fallback mode, Grafana can still be used as an interface to manage the configurations of Mimir Alertmanagers and view configurations of Prometheus Alertmanager, and those installations might not have migrated or being running on older versions. Such installations behave as if in classic mode, and Grafana must be able to parse their configurations to interact with them for some period of time. As such, Grafana uses fallback mode until we are ready to drop support for outdated installations of Mimir and the Prometheus Alertmanager.
62 lines
1.8 KiB
Go
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(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
|
|
}
|