MCPcopy Index your code
hub / github.com/coder/coder / NewMetrics

Function NewMetrics

coderd/notifications/metrics.go:37–80  ·  view source on GitHub ↗
(reg prometheus.Registerer)

Source from the content-addressed store, hash-verified

35)
36
37func NewMetrics(reg prometheus.Registerer) *Metrics {
38 return &Metrics{
39 DispatchAttempts: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
40 Name: "dispatch_attempts_total", Namespace: ns, Subsystem: subsystem,
41 Help: fmt.Sprintf("The number of dispatch attempts, aggregated by the result type (%s)",
42 strings.Join([]string{ResultSuccess, ResultTempFail, ResultPermFail}, ", ")),
43 }, []string{LabelMethod, LabelTemplateID, LabelResult}),
44 RetryCount: promauto.With(reg).NewCounterVec(prometheus.CounterOpts{
45 Name: "retry_count", Namespace: ns, Subsystem: subsystem,
46 Help: "The count of notification dispatch retry attempts.",
47 }, []string{LabelMethod, LabelTemplateID}),
48
49 // Aggregating on LabelTemplateID as well would cause a cardinality explosion.
50 QueuedSeconds: promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
51 Name: "queued_seconds", Namespace: ns, Subsystem: subsystem,
52 Buckets: []float64{1, 2.5, 5, 7.5, 10, 15, 20, 30, 60, 120, 300, 600, 3600},
53 Help: "The time elapsed between a notification being enqueued in the store and retrieved for dispatching " +
54 "(measures the latency of the notifications system). This should generally be within CODER_NOTIFICATIONS_FETCH_INTERVAL " +
55 "seconds; higher values for a sustained period indicates delayed processing and CODER_NOTIFICATIONS_LEASE_COUNT " +
56 "can be increased to accommodate this.",
57 }, []string{LabelMethod}),
58
59 InflightDispatches: promauto.With(reg).NewGaugeVec(prometheus.GaugeOpts{
60 Name: "inflight_dispatches", Namespace: ns, Subsystem: subsystem,
61 Help: "The number of dispatch attempts which are currently in progress.",
62 }, []string{LabelMethod, LabelTemplateID}),
63 // Aggregating on LabelTemplateID as well would cause a cardinality explosion.
64 DispatcherSendSeconds: promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{
65 Name: "dispatcher_send_seconds", Namespace: ns, Subsystem: subsystem,
66 Buckets: []float64{0.001, 0.05, 0.1, 0.5, 1, 2, 5, 10, 15, 30, 60, 120},
67 Help: "The time taken to dispatch notifications.",
68 }, []string{LabelMethod}),
69
70 // Currently no requirement to discriminate between success and failure updates which are pending.
71 PendingUpdates: promauto.With(reg).NewGauge(prometheus.GaugeOpts{
72 Name: "pending_updates", Namespace: ns, Subsystem: subsystem,
73 Help: "The number of dispatch attempt results waiting to be flushed to the store.",
74 }),
75 SyncedUpdates: promauto.With(reg).NewCounter(prometheus.CounterOpts{
76 Name: "synced_updates_total", Namespace: ns, Subsystem: subsystem,
77 Help: "The number of dispatch attempt results flushed to the store.",
78 }),
79 }
80}

Callers 6

createMetricsFunction · 0.92
TestMetricsFunction · 0.92
TestPendingUpdatesMetricFunction · 0.92
ServerMethod · 0.92

Calls

no outgoing calls

Tested by 5

createMetricsFunction · 0.74
TestMetricsFunction · 0.74
TestPendingUpdatesMetricFunction · 0.74