-
Notifications
You must be signed in to change notification settings - Fork 150
/
metrics.go
49 lines (41 loc) · 1.43 KB
/
metrics.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package controller
import (
"fmt"
"strconv"
"github.com/prometheus/client_golang/prometheus"
)
func NewMetricsRegistry(prefix string) *MetricsRegistry {
deliveriesCounter := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: fmt.Sprintf("%s_notifications_deliveries_total", prefix),
Help: "Number of delivered notifications.",
},
[]string{"trigger", "service", "succeeded"},
)
triggerEvaluationsCounter := prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: fmt.Sprintf("%s_notifications_trigger_eval_total", prefix),
Help: "Number of trigger evaluations.",
},
[]string{"name", "triggered"},
)
registry := &MetricsRegistry{
Registry: prometheus.NewRegistry(),
deliveriesCounter: deliveriesCounter,
triggerEvaluationsCounter: triggerEvaluationsCounter,
}
registry.MustRegister(deliveriesCounter)
registry.MustRegister(triggerEvaluationsCounter)
return registry
}
type MetricsRegistry struct {
*prometheus.Registry
deliveriesCounter *prometheus.CounterVec
triggerEvaluationsCounter *prometheus.CounterVec
}
func (r *MetricsRegistry) IncDeliveriesCounter(trigger string, service string, succeeded bool) {
r.deliveriesCounter.WithLabelValues(trigger, service, strconv.FormatBool(succeeded)).Inc()
}
func (r *MetricsRegistry) IncTriggerEvaluationsCounter(name string, triggered bool) {
r.triggerEvaluationsCounter.WithLabelValues(name, strconv.FormatBool(triggered)).Inc()
}