mirror of
https://github.com/prometheus/prometheus.git
synced 2026-01-24 18:11:03 +01:00
Migrate notifier package
Signed-off-by: Arthur Silva Sens <arthursens2005@gmail.com>
This commit is contained in:
parent
d79fc2655a
commit
8a068236e4
@ -26,6 +26,7 @@ import (
|
||||
|
||||
"github.com/prometheus/prometheus/config"
|
||||
"github.com/prometheus/prometheus/discovery/targetgroup"
|
||||
metrics "github.com/prometheus/prometheus/notifier/semconv"
|
||||
)
|
||||
|
||||
// alertmanagerSet contains a set of Alertmanagers discovered via a group of service
|
||||
@ -99,8 +100,8 @@ func (s *alertmanagerSet) sync(tgs []*targetgroup.Group) {
|
||||
}
|
||||
|
||||
// This will initialize the Counters for the AM to 0.
|
||||
s.metrics.sent.WithLabelValues(us)
|
||||
s.metrics.errors.WithLabelValues(us)
|
||||
s.metrics.sent.With(metrics.AlertmanagerAttr(us))
|
||||
s.metrics.errors.With(metrics.AlertmanagerAttr(us))
|
||||
|
||||
seen[us] = struct{}{}
|
||||
s.ams = append(s.ams, am)
|
||||
@ -111,10 +112,10 @@ func (s *alertmanagerSet) sync(tgs []*targetgroup.Group) {
|
||||
if _, ok := seen[us]; ok {
|
||||
continue
|
||||
}
|
||||
s.metrics.latencySummary.DeleteLabelValues(us)
|
||||
s.metrics.latencyHistogram.DeleteLabelValues(us)
|
||||
s.metrics.sent.DeleteLabelValues(us)
|
||||
s.metrics.errors.DeleteLabelValues(us)
|
||||
s.metrics.latencySummary.SummaryVec.DeleteLabelValues(us)
|
||||
s.metrics.latencyHistogram.HistogramVec.DeleteLabelValues(us)
|
||||
s.metrics.sent.CounterVec.DeleteLabelValues(us)
|
||||
s.metrics.errors.CounterVec.DeleteLabelValues(us)
|
||||
seen[us] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,6 +34,7 @@ import (
|
||||
"github.com/prometheus/prometheus/discovery/targetgroup"
|
||||
"github.com/prometheus/prometheus/model/labels"
|
||||
"github.com/prometheus/prometheus/model/relabel"
|
||||
metrics "github.com/prometheus/prometheus/notifier/semconv"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -493,15 +494,15 @@ func (n *Manager) sendAll(alerts ...*Alert) bool {
|
||||
err := n.sendOne(ctx, client, url, payload)
|
||||
if err != nil {
|
||||
n.logger.Error("Error sending alerts", "alertmanager", url, "count", count, "err", err)
|
||||
n.metrics.errors.WithLabelValues(url).Add(float64(count))
|
||||
n.metrics.errors.With(metrics.AlertmanagerAttr(url)).Add(float64(count))
|
||||
} else {
|
||||
amSetCovered.CompareAndSwap(k, false, true)
|
||||
}
|
||||
|
||||
durationSeconds := time.Since(begin).Seconds()
|
||||
n.metrics.latencySummary.WithLabelValues(url).Observe(durationSeconds)
|
||||
n.metrics.latencyHistogram.WithLabelValues(url).Observe(durationSeconds)
|
||||
n.metrics.sent.WithLabelValues(url).Add(float64(count))
|
||||
n.metrics.latencySummary.With(metrics.AlertmanagerAttr(url)).Observe(durationSeconds)
|
||||
n.metrics.latencyHistogram.With(metrics.AlertmanagerAttr(url)).Observe(durationSeconds)
|
||||
n.metrics.sent.With(metrics.AlertmanagerAttr(url)).Add(float64(count))
|
||||
|
||||
wg.Done()
|
||||
}(ctx, k, ams.client, am.url().String(), payload, len(amAlerts))
|
||||
|
||||
@ -14,19 +14,19 @@
|
||||
package notifier
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
metrics "github.com/prometheus/prometheus/notifier/semconv"
|
||||
)
|
||||
|
||||
type alertMetrics struct {
|
||||
latencySummary *prometheus.SummaryVec
|
||||
latencyHistogram *prometheus.HistogramVec
|
||||
errors *prometheus.CounterVec
|
||||
sent *prometheus.CounterVec
|
||||
dropped prometheus.Counter
|
||||
latencySummary metrics.PrometheusNotificationsLatencySeconds
|
||||
latencyHistogram metrics.PrometheusNotificationsLatencyHistogramSeconds
|
||||
errors metrics.PrometheusNotificationsErrorsTotal
|
||||
sent metrics.PrometheusNotificationsSentTotal
|
||||
dropped metrics.PrometheusNotificationsDroppedTotal
|
||||
queueLength prometheus.GaugeFunc
|
||||
queueCapacity prometheus.Gauge
|
||||
queueCapacity metrics.PrometheusNotificationsQueueCapacity
|
||||
alertmanagersDiscovered prometheus.GaugeFunc
|
||||
}
|
||||
|
||||
@ -36,62 +36,17 @@ func newAlertMetrics(
|
||||
queueLen, alertmanagersDiscovered func() float64,
|
||||
) *alertMetrics {
|
||||
m := &alertMetrics{
|
||||
latencySummary: prometheus.NewSummaryVec(prometheus.SummaryOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "latency_seconds",
|
||||
Help: "Latency quantiles for sending alert notifications.",
|
||||
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
|
||||
},
|
||||
[]string{alertmanagerLabel},
|
||||
),
|
||||
latencyHistogram: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "latency_histogram_seconds",
|
||||
Help: "Latency histogram for sending alert notifications.",
|
||||
|
||||
Buckets: []float64{.01, .1, 1, 10},
|
||||
NativeHistogramBucketFactor: 1.1,
|
||||
NativeHistogramMaxBucketNumber: 100,
|
||||
NativeHistogramMinResetDuration: 1 * time.Hour,
|
||||
},
|
||||
[]string{alertmanagerLabel},
|
||||
),
|
||||
errors: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "errors_total",
|
||||
Help: "Total number of sent alerts affected by errors.",
|
||||
},
|
||||
[]string{alertmanagerLabel},
|
||||
),
|
||||
sent: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "sent_total",
|
||||
Help: "Total number of alerts sent.",
|
||||
},
|
||||
[]string{alertmanagerLabel},
|
||||
),
|
||||
dropped: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "dropped_total",
|
||||
Help: "Total number of alerts dropped due to errors when sending to Alertmanager.",
|
||||
}),
|
||||
latencySummary: metrics.NewPrometheusNotificationsLatencySeconds(),
|
||||
latencyHistogram: metrics.NewPrometheusNotificationsLatencyHistogramSeconds(),
|
||||
errors: metrics.NewPrometheusNotificationsErrorsTotal(),
|
||||
sent: metrics.NewPrometheusNotificationsSentTotal(),
|
||||
dropped: metrics.NewPrometheusNotificationsDroppedTotal(),
|
||||
// GaugeFunc metrics require callbacks, so they remain manual
|
||||
queueLength: prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "queue_length",
|
||||
Help: "The number of alert notifications in the queue.",
|
||||
Name: "prometheus_notifications_queue_length",
|
||||
Help: "The number of alert notifications in the queue.",
|
||||
}, queueLen),
|
||||
queueCapacity: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "queue_capacity",
|
||||
Help: "The capacity of the alert notifications queue.",
|
||||
}),
|
||||
queueCapacity: metrics.NewPrometheusNotificationsQueueCapacity(),
|
||||
alertmanagersDiscovered: prometheus.NewGaugeFunc(prometheus.GaugeOpts{
|
||||
Name: "prometheus_notifications_alertmanagers_discovered",
|
||||
Help: "The number of alertmanagers discovered and active.",
|
||||
@ -102,13 +57,13 @@ func newAlertMetrics(
|
||||
|
||||
if r != nil {
|
||||
r.MustRegister(
|
||||
m.latencySummary,
|
||||
m.latencyHistogram,
|
||||
m.errors,
|
||||
m.sent,
|
||||
m.dropped,
|
||||
m.latencySummary.SummaryVec,
|
||||
m.latencyHistogram.HistogramVec,
|
||||
m.errors.CounterVec,
|
||||
m.sent.CounterVec,
|
||||
m.dropped.Counter,
|
||||
m.queueLength,
|
||||
m.queueCapacity,
|
||||
m.queueCapacity.Gauge,
|
||||
m.alertmanagersDiscovered,
|
||||
)
|
||||
}
|
||||
|
||||
@ -8,8 +8,12 @@ This document describes the metrics defined in this semantic convention registry
|
||||
|--------|------|------|-------------|
|
||||
| `prometheus_notifications_alertmanagers_discovered` | gauge | {alertmanager} | The number of alertmanagers discovered and active. |
|
||||
| `prometheus_notifications_dropped_total` | counter | {notification} | Total number of alerts dropped due to errors when sending to Alertmanager. |
|
||||
| `prometheus_notifications_errors_total` | counter | {notification} | Total number of sent alerts affected by errors. |
|
||||
| `prometheus_notifications_latency_histogram_seconds` | histogram | s | Latency histogram for sending alert notifications. |
|
||||
| `prometheus_notifications_latency_seconds` | histogram | s | Latency quantiles for sending alert notifications. |
|
||||
| `prometheus_notifications_queue_capacity` | gauge | {notification} | The capacity of the alert notifications queue. |
|
||||
| `prometheus_notifications_queue_length` | gauge | {notification} | The number of alert notifications in the queue. |
|
||||
| `prometheus_notifications_sent_total` | counter | {notification} | Total number of alerts sent. |
|
||||
|
||||
|
||||
## Metric Details
|
||||
@ -33,6 +37,54 @@ Total number of alerts dropped due to errors when sending to Alertmanager.
|
||||
- **Stability:** development
|
||||
|
||||
|
||||
### `prometheus_notifications_errors_total`
|
||||
|
||||
Total number of sent alerts affected by errors.
|
||||
|
||||
- **Type:** counter
|
||||
- **Unit:** {notification}
|
||||
- **Stability:** development
|
||||
|
||||
#### Attributes
|
||||
|
||||
| Attribute | Type | Description | Examples |
|
||||
|-----------|------|-------------|----------|
|
||||
| `alertmanager` | string | The alertmanager instance URL. | http://alertmanager:9093/api/v2/alerts |
|
||||
|
||||
|
||||
|
||||
### `prometheus_notifications_latency_histogram_seconds`
|
||||
|
||||
Latency histogram for sending alert notifications.
|
||||
|
||||
- **Type:** histogram
|
||||
- **Unit:** s
|
||||
- **Stability:** development
|
||||
|
||||
#### Attributes
|
||||
|
||||
| Attribute | Type | Description | Examples |
|
||||
|-----------|------|-------------|----------|
|
||||
| `alertmanager` | string | The alertmanager instance URL. | http://alertmanager:9093/api/v2/alerts |
|
||||
|
||||
|
||||
|
||||
### `prometheus_notifications_latency_seconds`
|
||||
|
||||
Latency quantiles for sending alert notifications.
|
||||
|
||||
- **Type:** histogram
|
||||
- **Unit:** s
|
||||
- **Stability:** development
|
||||
|
||||
#### Attributes
|
||||
|
||||
| Attribute | Type | Description | Examples |
|
||||
|-----------|------|-------------|----------|
|
||||
| `alertmanager` | string | The alertmanager instance URL. | http://alertmanager:9093/api/v2/alerts |
|
||||
|
||||
|
||||
|
||||
### `prometheus_notifications_queue_capacity`
|
||||
|
||||
The capacity of the alert notifications queue.
|
||||
@ -49,3 +101,19 @@ The number of alert notifications in the queue.
|
||||
- **Type:** gauge
|
||||
- **Unit:** {notification}
|
||||
- **Stability:** development
|
||||
|
||||
|
||||
### `prometheus_notifications_sent_total`
|
||||
|
||||
Total number of alerts sent.
|
||||
|
||||
- **Type:** counter
|
||||
- **Unit:** {notification}
|
||||
- **Stability:** development
|
||||
|
||||
#### Attributes
|
||||
|
||||
| Attribute | Type | Description | Examples |
|
||||
|-----------|------|-------------|----------|
|
||||
| `alertmanager` | string | The alertmanager instance URL. | http://alertmanager:9093/api/v2/alerts |
|
||||
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@ -13,6 +15,15 @@ type Attribute interface {
|
||||
ID() string
|
||||
Value() string
|
||||
}
|
||||
type AlertmanagerAttr string
|
||||
|
||||
func (a AlertmanagerAttr) ID() string {
|
||||
return "alertmanager"
|
||||
}
|
||||
|
||||
func (a AlertmanagerAttr) Value() string {
|
||||
return string(a)
|
||||
}
|
||||
|
||||
// PrometheusNotificationsAlertmanagersDiscovered records the number of alertmanagers discovered and active.
|
||||
type PrometheusNotificationsAlertmanagersDiscovered struct {
|
||||
@ -44,6 +55,126 @@ func NewPrometheusNotificationsDroppedTotal() PrometheusNotificationsDroppedTota
|
||||
}
|
||||
}
|
||||
|
||||
// PrometheusNotificationsErrorsTotal records the total number of sent alerts affected by errors.
|
||||
type PrometheusNotificationsErrorsTotal struct {
|
||||
*prometheus.CounterVec
|
||||
}
|
||||
|
||||
// NewPrometheusNotificationsErrorsTotal returns a new PrometheusNotificationsErrorsTotal instrument.
|
||||
func NewPrometheusNotificationsErrorsTotal() PrometheusNotificationsErrorsTotal {
|
||||
labels := []string{
|
||||
"alertmanager",
|
||||
}
|
||||
return PrometheusNotificationsErrorsTotal{
|
||||
CounterVec: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "prometheus_notifications_errors_total",
|
||||
Help: "Total number of sent alerts affected by errors.",
|
||||
}, labels),
|
||||
}
|
||||
}
|
||||
|
||||
type PrometheusNotificationsErrorsTotalAttr interface {
|
||||
Attribute
|
||||
implPrometheusNotificationsErrorsTotal()
|
||||
}
|
||||
|
||||
func (a AlertmanagerAttr) implPrometheusNotificationsErrorsTotal() {}
|
||||
|
||||
func (m PrometheusNotificationsErrorsTotal) With(
|
||||
extra ...PrometheusNotificationsErrorsTotalAttr,
|
||||
) prometheus.Counter {
|
||||
labels := prometheus.Labels{
|
||||
"alertmanager": "",
|
||||
}
|
||||
for _, v := range extra {
|
||||
labels[v.ID()] = v.Value()
|
||||
}
|
||||
return m.CounterVec.With(labels)
|
||||
}
|
||||
|
||||
// PrometheusNotificationsLatencyHistogramSeconds records the latency histogram for sending alert notifications.
|
||||
type PrometheusNotificationsLatencyHistogramSeconds struct {
|
||||
*prometheus.HistogramVec
|
||||
}
|
||||
|
||||
// NewPrometheusNotificationsLatencyHistogramSeconds returns a new PrometheusNotificationsLatencyHistogramSeconds instrument.
|
||||
func NewPrometheusNotificationsLatencyHistogramSeconds() PrometheusNotificationsLatencyHistogramSeconds {
|
||||
labels := []string{
|
||||
"alertmanager",
|
||||
}
|
||||
return PrometheusNotificationsLatencyHistogramSeconds{
|
||||
HistogramVec: prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Name: "prometheus_notifications_latency_histogram_seconds",
|
||||
Help: "Latency histogram for sending alert notifications.",
|
||||
Buckets: []float64{0.01, 0.1, 1, 10},
|
||||
NativeHistogramBucketFactor: 1.1,
|
||||
NativeHistogramMaxBucketNumber: 100,
|
||||
NativeHistogramMinResetDuration: 1 * time.Hour,
|
||||
}, labels),
|
||||
}
|
||||
}
|
||||
|
||||
type PrometheusNotificationsLatencyHistogramSecondsAttr interface {
|
||||
Attribute
|
||||
implPrometheusNotificationsLatencyHistogramSeconds()
|
||||
}
|
||||
|
||||
func (a AlertmanagerAttr) implPrometheusNotificationsLatencyHistogramSeconds() {}
|
||||
|
||||
func (m PrometheusNotificationsLatencyHistogramSeconds) With(
|
||||
extra ...PrometheusNotificationsLatencyHistogramSecondsAttr,
|
||||
) prometheus.Observer {
|
||||
labels := prometheus.Labels{
|
||||
"alertmanager": "",
|
||||
}
|
||||
for _, v := range extra {
|
||||
labels[v.ID()] = v.Value()
|
||||
}
|
||||
return m.HistogramVec.With(labels)
|
||||
}
|
||||
|
||||
// PrometheusNotificationsLatencySeconds records the latency quantiles for sending alert notifications.
|
||||
type PrometheusNotificationsLatencySeconds struct {
|
||||
*prometheus.SummaryVec
|
||||
}
|
||||
|
||||
// NewPrometheusNotificationsLatencySeconds returns a new PrometheusNotificationsLatencySeconds instrument.
|
||||
func NewPrometheusNotificationsLatencySeconds() PrometheusNotificationsLatencySeconds {
|
||||
labels := []string{
|
||||
"alertmanager",
|
||||
}
|
||||
return PrometheusNotificationsLatencySeconds{
|
||||
SummaryVec: prometheus.NewSummaryVec(prometheus.SummaryOpts{
|
||||
Name: "prometheus_notifications_latency_seconds",
|
||||
Help: "Latency quantiles for sending alert notifications.",
|
||||
Objectives: map[float64]float64{
|
||||
0.5: 0.05,
|
||||
0.9: 0.01,
|
||||
0.99: 0.001,
|
||||
},
|
||||
}, labels),
|
||||
}
|
||||
}
|
||||
|
||||
type PrometheusNotificationsLatencySecondsAttr interface {
|
||||
Attribute
|
||||
implPrometheusNotificationsLatencySeconds()
|
||||
}
|
||||
|
||||
func (a AlertmanagerAttr) implPrometheusNotificationsLatencySeconds() {}
|
||||
|
||||
func (m PrometheusNotificationsLatencySeconds) With(
|
||||
extra ...PrometheusNotificationsLatencySecondsAttr,
|
||||
) prometheus.Observer {
|
||||
labels := prometheus.Labels{
|
||||
"alertmanager": "",
|
||||
}
|
||||
for _, v := range extra {
|
||||
labels[v.ID()] = v.Value()
|
||||
}
|
||||
return m.SummaryVec.With(labels)
|
||||
}
|
||||
|
||||
// PrometheusNotificationsQueueCapacity records the capacity of the alert notifications queue.
|
||||
type PrometheusNotificationsQueueCapacity struct {
|
||||
prometheus.Gauge
|
||||
@ -73,3 +204,40 @@ func NewPrometheusNotificationsQueueLength() PrometheusNotificationsQueueLength
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// PrometheusNotificationsSentTotal records the total number of alerts sent.
|
||||
type PrometheusNotificationsSentTotal struct {
|
||||
*prometheus.CounterVec
|
||||
}
|
||||
|
||||
// NewPrometheusNotificationsSentTotal returns a new PrometheusNotificationsSentTotal instrument.
|
||||
func NewPrometheusNotificationsSentTotal() PrometheusNotificationsSentTotal {
|
||||
labels := []string{
|
||||
"alertmanager",
|
||||
}
|
||||
return PrometheusNotificationsSentTotal{
|
||||
CounterVec: prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Name: "prometheus_notifications_sent_total",
|
||||
Help: "Total number of alerts sent.",
|
||||
}, labels),
|
||||
}
|
||||
}
|
||||
|
||||
type PrometheusNotificationsSentTotalAttr interface {
|
||||
Attribute
|
||||
implPrometheusNotificationsSentTotal()
|
||||
}
|
||||
|
||||
func (a AlertmanagerAttr) implPrometheusNotificationsSentTotal() {}
|
||||
|
||||
func (m PrometheusNotificationsSentTotal) With(
|
||||
extra ...PrometheusNotificationsSentTotalAttr,
|
||||
) prometheus.Counter {
|
||||
labels := prometheus.Labels{
|
||||
"alertmanager": "",
|
||||
}
|
||||
for _, v := range extra {
|
||||
labels[v.ID()] = v.Value()
|
||||
}
|
||||
return m.CounterVec.With(labels)
|
||||
}
|
||||
|
||||
@ -4,6 +4,19 @@
|
||||
# Run `make generate-semconv` to regenerate the Go code.
|
||||
|
||||
groups:
|
||||
# Attribute definition for alertmanager label
|
||||
- id: attr.alertmanager
|
||||
type: attribute_group
|
||||
brief: Attributes for alertmanager metrics.
|
||||
attributes:
|
||||
- id: alertmanager
|
||||
type: string
|
||||
stability: development
|
||||
brief: The alertmanager instance URL.
|
||||
examples:
|
||||
- "http://alertmanager:9093/api/v2/alerts"
|
||||
|
||||
# Simple metrics (no labels)
|
||||
- id: metric.prometheus_notifications_alertmanagers_discovered
|
||||
type: metric
|
||||
stability: development
|
||||
@ -11,6 +24,7 @@ groups:
|
||||
metric_name: prometheus_notifications_alertmanagers_discovered
|
||||
instrument: gauge
|
||||
unit: "{alertmanager}"
|
||||
# Note: This is implemented as GaugeFunc in code (requires callback)
|
||||
|
||||
- id: metric.prometheus_notifications_dropped_total
|
||||
type: metric
|
||||
@ -35,3 +49,59 @@ groups:
|
||||
metric_name: prometheus_notifications_queue_length
|
||||
instrument: gauge
|
||||
unit: "{notification}"
|
||||
# Note: This is implemented as GaugeFunc in code (requires callback)
|
||||
|
||||
# Metrics with alertmanager label
|
||||
- id: metric.prometheus_notifications_errors_total
|
||||
type: metric
|
||||
stability: development
|
||||
brief: Total number of sent alerts affected by errors.
|
||||
metric_name: prometheus_notifications_errors_total
|
||||
instrument: counter
|
||||
unit: "{notification}"
|
||||
attributes:
|
||||
- ref: alertmanager
|
||||
|
||||
- id: metric.prometheus_notifications_sent_total
|
||||
type: metric
|
||||
stability: development
|
||||
brief: Total number of alerts sent.
|
||||
metric_name: prometheus_notifications_sent_total
|
||||
instrument: counter
|
||||
unit: "{notification}"
|
||||
attributes:
|
||||
- ref: alertmanager
|
||||
|
||||
- id: metric.prometheus_notifications_latency_seconds
|
||||
type: metric
|
||||
stability: development
|
||||
brief: Latency quantiles for sending alert notifications.
|
||||
metric_name: prometheus_notifications_latency_seconds
|
||||
instrument: histogram
|
||||
unit: s
|
||||
attributes:
|
||||
- ref: alertmanager
|
||||
annotations:
|
||||
prometheus:
|
||||
histogram_type: summary
|
||||
objectives:
|
||||
0.5: 0.05
|
||||
0.9: 0.01
|
||||
0.99: 0.001
|
||||
|
||||
- id: metric.prometheus_notifications_latency_histogram_seconds
|
||||
type: metric
|
||||
stability: development
|
||||
brief: Latency histogram for sending alert notifications.
|
||||
metric_name: prometheus_notifications_latency_histogram_seconds
|
||||
instrument: histogram
|
||||
unit: s
|
||||
attributes:
|
||||
- ref: alertmanager
|
||||
annotations:
|
||||
prometheus:
|
||||
histogram_type: mixed_histogram
|
||||
buckets: [0.01, 0.1, 1, 10]
|
||||
bucket_factor: 1.1
|
||||
max_bucket_number: 100
|
||||
min_reset_duration: "1h"
|
||||
|
||||
@ -18,6 +18,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
||||
metrics "github.com/prometheus/prometheus/util/notifications/semconv"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -41,38 +43,23 @@ type Notifications struct {
|
||||
subscribers map[chan Notification]struct{} // Active subscribers.
|
||||
maxSubscribers int
|
||||
|
||||
subscriberGauge prometheus.Gauge
|
||||
notificationsSent prometheus.Counter
|
||||
notificationsDropped prometheus.Counter
|
||||
subscriberGauge metrics.PrometheusAPINotificationActiveSubscribers
|
||||
notificationsSent metrics.PrometheusAPINotificationUpdatesSentTotal
|
||||
notificationsDropped metrics.PrometheusAPINotificationUpdatesDroppedTotal
|
||||
}
|
||||
|
||||
// NewNotifications creates a new Notifications instance.
|
||||
func NewNotifications(maxSubscribers int, reg prometheus.Registerer) *Notifications {
|
||||
n := &Notifications{
|
||||
subscribers: make(map[chan Notification]struct{}),
|
||||
maxSubscribers: maxSubscribers,
|
||||
subscriberGauge: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: "prometheus",
|
||||
Subsystem: "api",
|
||||
Name: "notification_active_subscribers",
|
||||
Help: "The current number of active notification subscribers.",
|
||||
}),
|
||||
notificationsSent: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "prometheus",
|
||||
Subsystem: "api",
|
||||
Name: "notification_updates_sent_total",
|
||||
Help: "Total number of notification updates sent.",
|
||||
}),
|
||||
notificationsDropped: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: "prometheus",
|
||||
Subsystem: "api",
|
||||
Name: "notification_updates_dropped_total",
|
||||
Help: "Total number of notification updates dropped.",
|
||||
}),
|
||||
subscribers: make(map[chan Notification]struct{}),
|
||||
maxSubscribers: maxSubscribers,
|
||||
subscriberGauge: metrics.NewPrometheusAPINotificationActiveSubscribers(),
|
||||
notificationsSent: metrics.NewPrometheusAPINotificationUpdatesSentTotal(),
|
||||
notificationsDropped: metrics.NewPrometheusAPINotificationUpdatesDroppedTotal(),
|
||||
}
|
||||
|
||||
if reg != nil {
|
||||
reg.MustRegister(n.subscriberGauge, n.notificationsSent, n.notificationsDropped)
|
||||
reg.MustRegister(n.subscriberGauge.Gauge, n.notificationsSent.Counter, n.notificationsDropped.Counter)
|
||||
}
|
||||
|
||||
return n
|
||||
|
||||
41
util/notifications/semconv/README.md
Normal file
41
util/notifications/semconv/README.md
Normal file
@ -0,0 +1,41 @@
|
||||
<!-- Code generated from semantic convention specification. DO NOT EDIT. -->
|
||||
|
||||
# Metrics
|
||||
|
||||
This document describes the metrics defined in this semantic convention registry.
|
||||
|
||||
| Metric | Type | Unit | Description |
|
||||
|--------|------|------|-------------|
|
||||
| `prometheus_api_notification_active_subscribers` | gauge | {subscriber} | The current number of active notification subscribers. |
|
||||
| `prometheus_api_notification_updates_dropped_total` | counter | {update} | Total number of notification updates dropped. |
|
||||
| `prometheus_api_notification_updates_sent_total` | counter | {update} | Total number of notification updates sent. |
|
||||
|
||||
|
||||
## Metric Details
|
||||
|
||||
|
||||
### `prometheus_api_notification_active_subscribers`
|
||||
|
||||
The current number of active notification subscribers.
|
||||
|
||||
- **Type:** gauge
|
||||
- **Unit:** {subscriber}
|
||||
- **Stability:** development
|
||||
|
||||
|
||||
### `prometheus_api_notification_updates_dropped_total`
|
||||
|
||||
Total number of notification updates dropped.
|
||||
|
||||
- **Type:** counter
|
||||
- **Unit:** {update}
|
||||
- **Stability:** development
|
||||
|
||||
|
||||
### `prometheus_api_notification_updates_sent_total`
|
||||
|
||||
Total number of notification updates sent.
|
||||
|
||||
- **Type:** counter
|
||||
- **Unit:** {update}
|
||||
- **Stability:** development
|
||||
60
util/notifications/semconv/metrics.go
Normal file
60
util/notifications/semconv/metrics.go
Normal file
@ -0,0 +1,60 @@
|
||||
// Code generated from semantic convention specification. DO NOT EDIT.
|
||||
|
||||
// Package metrics provides Prometheus instrumentation types for metrics
|
||||
// defined in this semantic convention registry.
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// Attribute is an interface for metric label attributes.
|
||||
type Attribute interface {
|
||||
ID() string
|
||||
Value() string
|
||||
}
|
||||
|
||||
// PrometheusAPINotificationActiveSubscribers records the current number of active notification subscribers.
|
||||
type PrometheusAPINotificationActiveSubscribers struct {
|
||||
prometheus.Gauge
|
||||
}
|
||||
|
||||
// NewPrometheusAPINotificationActiveSubscribers returns a new PrometheusAPINotificationActiveSubscribers instrument.
|
||||
func NewPrometheusAPINotificationActiveSubscribers() PrometheusAPINotificationActiveSubscribers {
|
||||
return PrometheusAPINotificationActiveSubscribers{
|
||||
Gauge: prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "prometheus_api_notification_active_subscribers",
|
||||
Help: "The current number of active notification subscribers.",
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// PrometheusAPINotificationUpdatesDroppedTotal records the total number of notification updates dropped.
|
||||
type PrometheusAPINotificationUpdatesDroppedTotal struct {
|
||||
prometheus.Counter
|
||||
}
|
||||
|
||||
// NewPrometheusAPINotificationUpdatesDroppedTotal returns a new PrometheusAPINotificationUpdatesDroppedTotal instrument.
|
||||
func NewPrometheusAPINotificationUpdatesDroppedTotal() PrometheusAPINotificationUpdatesDroppedTotal {
|
||||
return PrometheusAPINotificationUpdatesDroppedTotal{
|
||||
Counter: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "prometheus_api_notification_updates_dropped_total",
|
||||
Help: "Total number of notification updates dropped.",
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
// PrometheusAPINotificationUpdatesSentTotal records the total number of notification updates sent.
|
||||
type PrometheusAPINotificationUpdatesSentTotal struct {
|
||||
prometheus.Counter
|
||||
}
|
||||
|
||||
// NewPrometheusAPINotificationUpdatesSentTotal returns a new PrometheusAPINotificationUpdatesSentTotal instrument.
|
||||
func NewPrometheusAPINotificationUpdatesSentTotal() PrometheusAPINotificationUpdatesSentTotal {
|
||||
return PrometheusAPINotificationUpdatesSentTotal{
|
||||
Counter: prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Name: "prometheus_api_notification_updates_sent_total",
|
||||
Help: "Total number of notification updates sent.",
|
||||
}),
|
||||
}
|
||||
}
|
||||
29
util/notifications/semconv/registry.yaml
Normal file
29
util/notifications/semconv/registry.yaml
Normal file
@ -0,0 +1,29 @@
|
||||
# Semantic convention registry for Prometheus API notification metrics.
|
||||
#
|
||||
# This file is the source of truth for these metrics.
|
||||
# Run `make generate-semconv` to regenerate the Go code.
|
||||
|
||||
groups:
|
||||
- id: metric.prometheus_api_notification_active_subscribers
|
||||
type: metric
|
||||
stability: development
|
||||
brief: The current number of active notification subscribers.
|
||||
metric_name: prometheus_api_notification_active_subscribers
|
||||
instrument: gauge
|
||||
unit: "{subscriber}"
|
||||
|
||||
- id: metric.prometheus_api_notification_updates_dropped_total
|
||||
type: metric
|
||||
stability: development
|
||||
brief: Total number of notification updates dropped.
|
||||
metric_name: prometheus_api_notification_updates_dropped_total
|
||||
instrument: counter
|
||||
unit: "{update}"
|
||||
|
||||
- id: metric.prometheus_api_notification_updates_sent_total
|
||||
type: metric
|
||||
stability: development
|
||||
brief: Total number of notification updates sent.
|
||||
metric_name: prometheus_api_notification_updates_sent_total
|
||||
instrument: counter
|
||||
unit: "{update}"
|
||||
Loading…
x
Reference in New Issue
Block a user