-
Notifications
You must be signed in to change notification settings - Fork 849
add per-tenant alertmanager metrics #2124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jtlisi
merged 7 commits into
cortexproject:master
from
jtlisi:20200211_pertenant_am_metrics
Mar 2, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
380f407
add per-tenant alertmanager metrics
jtlisi 3bece6c
fix linting error
jtlisi 20cfea6
update in regards to PR comments
jtlisi ef6b4ff
fix double lock
jtlisi 87bf3d4
adjust cortex_alertmanager_alerts_received_total to be per user
jtlisi f50885f
make isActive public function and fix typo
jtlisi cabeb79
comment IsActive
jtlisi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| package alertmanager | ||
|
|
||
| import ( | ||
| "sync" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
|
|
||
| "github.com/cortexproject/cortex/pkg/util" | ||
| ) | ||
|
|
||
| // This struct aggregates metrics exported by Alertmanager | ||
| // and re-exports those aggregates as Cortex metrics. | ||
| type alertmanagerMetrics struct { | ||
| // Maps userID -> registry | ||
| regsMu sync.Mutex | ||
| regs map[string]*prometheus.Registry | ||
|
|
||
| // exported metrics, gathered from Alertmanager API | ||
| alertsReceived *prometheus.Desc | ||
| alertsInvalid *prometheus.Desc | ||
|
|
||
| // exported metrics, gathered from Alertmanager PipelineBuilder | ||
| numNotifications *prometheus.Desc | ||
| numFailedNotifications *prometheus.Desc | ||
| notificationLatencySeconds *prometheus.Desc | ||
|
|
||
| // exported metrics, gathered from Alertmanager nflog | ||
| nflogGCDuration *prometheus.Desc | ||
| nflogSnapshotDuration *prometheus.Desc | ||
| nflogSnapshotSize *prometheus.Desc | ||
| nflogQueriesTotal *prometheus.Desc | ||
| nflogQueryErrorsTotal *prometheus.Desc | ||
| nflogQueryDuration *prometheus.Desc | ||
| nflogPropagatedMessagesTotal *prometheus.Desc | ||
|
|
||
| // exported metrics, gathered from Alertmanager Marker | ||
| markerAlerts *prometheus.Desc | ||
|
|
||
| // exported metrics, gathered from Alertmanager Silences | ||
| silencesGCDuration *prometheus.Desc | ||
| silencesSnapshotDuration *prometheus.Desc | ||
| silencesSnapshotSize *prometheus.Desc | ||
| silencesQueriesTotal *prometheus.Desc | ||
| silencesQueryErrorsTotal *prometheus.Desc | ||
| silencesQueryDuration *prometheus.Desc | ||
| silences *prometheus.Desc | ||
| silencesPropagatedMessagesTotal *prometheus.Desc | ||
| } | ||
|
|
||
| func newAlertmanagerMetrics() *alertmanagerMetrics { | ||
| return &alertmanagerMetrics{ | ||
| regs: map[string]*prometheus.Registry{}, | ||
| regsMu: sync.Mutex{}, | ||
| alertsReceived: prometheus.NewDesc( | ||
| "cortex_alertmanager_alerts_received_total", | ||
| "The total number of received alerts.", | ||
| []string{"user"}, nil), | ||
| alertsInvalid: prometheus.NewDesc( | ||
| "cortex_alertmanager_alerts_invalid_total", | ||
| "The total number of received alerts that were invalid.", | ||
| []string{"user"}, nil), | ||
| numNotifications: prometheus.NewDesc( | ||
| "cortex_alertmanager_notifications_total", | ||
| "The total number of attempted notifications.", | ||
| []string{"user"}, nil), | ||
| numFailedNotifications: prometheus.NewDesc( | ||
| "cortex_alertmanager_notifications_failed_total", | ||
| "The total number of failed notifications.", | ||
| []string{"user"}, nil), | ||
| notificationLatencySeconds: prometheus.NewDesc( | ||
| "cortex_alertmanager_notification_latency_seconds", | ||
| "The latency of notifications in seconds.", | ||
| nil, nil), | ||
| nflogGCDuration: prometheus.NewDesc( | ||
| "cortex_alertmanager_nflog_gc_duration_seconds", | ||
| "Duration of the last notification log garbage collection cycle.", | ||
| nil, nil), | ||
| nflogSnapshotDuration: prometheus.NewDesc( | ||
| "cortex_alertmanager_nflog_snapshot_duration_seconds", | ||
| "Duration of the last notification log snapshot.", | ||
| nil, nil), | ||
| nflogSnapshotSize: prometheus.NewDesc( | ||
| "cortex_alertmanager_nflog_snapshot_size_bytes", | ||
| "Size of the last notification log snapshot in bytes.", | ||
| nil, nil), | ||
| nflogQueriesTotal: prometheus.NewDesc( | ||
| "cortex_alertmanager_nflog_queries_total", | ||
| "Number of notification log queries were received.", | ||
| nil, nil), | ||
| nflogQueryErrorsTotal: prometheus.NewDesc( | ||
| "cortex_alertmanager_nflog_query_errors_total", | ||
| "Number notification log received queries that failed.", | ||
| nil, nil), | ||
| nflogQueryDuration: prometheus.NewDesc( | ||
| "cortex_alertmanager_nflog_query_duration_seconds", | ||
| "Duration of notification log query evaluation.", | ||
| nil, nil), | ||
| nflogPropagatedMessagesTotal: prometheus.NewDesc( | ||
| "cortex_alertmanager_nflog_gossip_messages_propagated_total", | ||
| "Number of received gossip messages that have been further gossiped.", | ||
| nil, nil), | ||
| markerAlerts: prometheus.NewDesc( | ||
| "cortex_alertmanager_alerts", | ||
| "How many alerts by state.", | ||
| []string{"user", "state"}, nil), | ||
| silencesGCDuration: prometheus.NewDesc( | ||
| "cortex_alertmanager_silences_gc_duration_seconds", | ||
| "Duration of the last silence garbage collection cycle.", | ||
| nil, nil), | ||
| silencesSnapshotDuration: prometheus.NewDesc( | ||
| "cortex_alertmanager_silences_snapshot_duration_seconds", | ||
| "Duration of the last silence snapshot.", | ||
| nil, nil), | ||
| silencesSnapshotSize: prometheus.NewDesc( | ||
| "cortex_alertmanager_silences_snapshot_size_bytes", | ||
| "Size of the last silence snapshot in bytes.", | ||
| nil, nil), | ||
| silencesQueriesTotal: prometheus.NewDesc( | ||
| "cortex_alertmanager_silences_queries_total", | ||
| "How many silence queries were received.", | ||
| nil, nil), | ||
| silencesQueryErrorsTotal: prometheus.NewDesc( | ||
| "cortex_alertmanager_silences_query_errors_total", | ||
| "How many silence received queries did not succeed.", | ||
| nil, nil), | ||
| silencesQueryDuration: prometheus.NewDesc( | ||
| "cortex_alertmanager_silences_query_duration_seconds", | ||
| "Duration of silence query evaluation.", | ||
| nil, nil), | ||
| silencesPropagatedMessagesTotal: prometheus.NewDesc( | ||
| "cortex_alertmanager_silences_gossip_messages_propagated_total", | ||
| "Number of received gossip messages that have been further gossiped.", | ||
| nil, nil), | ||
| silences: prometheus.NewDesc( | ||
| "cortex_alertmanager_silences", | ||
| "How many silences by state.", | ||
| []string{"user", "state"}, nil), | ||
| } | ||
| } | ||
|
|
||
| func (m *alertmanagerMetrics) addUserRegistry(user string, reg *prometheus.Registry) { | ||
| m.regsMu.Lock() | ||
| m.regs[user] = reg | ||
| m.regsMu.Unlock() | ||
| } | ||
|
|
||
| func (m *alertmanagerMetrics) registries() map[string]*prometheus.Registry { | ||
| regs := map[string]*prometheus.Registry{} | ||
|
|
||
| m.regsMu.Lock() | ||
| defer m.regsMu.Unlock() | ||
| for uid, r := range m.regs { | ||
| regs[uid] = r | ||
| } | ||
|
|
||
| return regs | ||
| } | ||
|
|
||
| func (m *alertmanagerMetrics) Describe(out chan<- *prometheus.Desc) { | ||
| out <- m.alertsReceived | ||
| out <- m.alertsInvalid | ||
| out <- m.numNotifications | ||
| out <- m.numFailedNotifications | ||
| out <- m.notificationLatencySeconds | ||
| out <- m.nflogGCDuration | ||
| out <- m.nflogSnapshotDuration | ||
| out <- m.nflogSnapshotSize | ||
| out <- m.nflogQueriesTotal | ||
| out <- m.nflogQueryErrorsTotal | ||
| out <- m.nflogQueryDuration | ||
| out <- m.nflogPropagatedMessagesTotal | ||
| out <- m.markerAlerts | ||
| out <- m.silencesGCDuration | ||
| out <- m.silencesSnapshotDuration | ||
| out <- m.silencesSnapshotSize | ||
| out <- m.silencesQueriesTotal | ||
| out <- m.silencesQueryErrorsTotal | ||
| out <- m.silencesQueryDuration | ||
| out <- m.silences | ||
| out <- m.silencesPropagatedMessagesTotal | ||
| } | ||
|
|
||
| func (m *alertmanagerMetrics) Collect(out chan<- prometheus.Metric) { | ||
| data := util.BuildMetricFamiliesPerUserFromUserRegistries(m.registries()) | ||
|
|
||
| data.SendSumOfCountersPerUser(out, m.alertsReceived, "alertmanager_alerts_received_total") | ||
| data.SendSumOfCountersPerUser(out, m.alertsInvalid, "alertmanager_alerts_invalid_total") | ||
|
|
||
| data.SendSumOfCountersPerUser(out, m.numNotifications, "alertmanager_notifications_total") | ||
| data.SendSumOfCountersPerUser(out, m.numFailedNotifications, "alertmanager_notifications_failed_total") | ||
| data.SendSumOfHistograms(out, m.notificationLatencySeconds, "alertmanager_notification_latency_seconds") | ||
| data.SendSumOfGaugesPerUserWithLabels(out, m.markerAlerts, "alertmanager_alerts", "state") | ||
|
|
||
| data.SendSumOfSummaries(out, m.nflogGCDuration, "alertmanager_nflog_gc_duration_seconds") | ||
| data.SendSumOfSummaries(out, m.nflogSnapshotDuration, "alertmanager_nflog_snapshot_duration_seconds") | ||
| data.SendSumOfGauges(out, m.nflogSnapshotSize, "alertmanager_nflog_snapshot_size_bytes") | ||
| data.SendSumOfCounters(out, m.nflogQueriesTotal, "alertmanager_nflog_queries_total") | ||
| data.SendSumOfCounters(out, m.nflogQueryErrorsTotal, "alertmanager_nflog_query_errors_total") | ||
| data.SendSumOfHistograms(out, m.nflogQueryDuration, "alertmanager_nflog_query_duration_seconds") | ||
| data.SendSumOfCounters(out, m.nflogPropagatedMessagesTotal, "alertmanager_nflog_gossip_messages_propagated_total") | ||
|
|
||
| data.SendSumOfSummaries(out, m.silencesGCDuration, "alertmanager_silences_gc_duration_seconds") | ||
| data.SendSumOfSummaries(out, m.silencesSnapshotDuration, "alertmanager_silences_snapshot_duration_seconds") | ||
| data.SendSumOfGauges(out, m.silencesSnapshotSize, "alertmanager_silences_snapshot_size_bytes") | ||
| data.SendSumOfCounters(out, m.silencesQueriesTotal, "alertmanager_silences_queries_total") | ||
| data.SendSumOfCounters(out, m.silencesQueryErrorsTotal, "alertmanager_silences_query_errors_total") | ||
| data.SendSumOfHistograms(out, m.silencesQueryDuration, "alertmanager_silences_query_duration_seconds") | ||
| data.SendSumOfCounters(out, m.silencesPropagatedMessagesTotal, "alertmanager_silences_gossip_messages_propagated_total") | ||
| data.SendSumOfGaugesPerUserWithLabels(out, m.silences, "alertmanager_silences", "state") | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.