-
Notifications
You must be signed in to change notification settings - Fork 26
/
metrics.go
49 lines (43 loc) · 1.23 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 webhook
import (
"github.com/go-kit/kit/metrics"
"github.com/xmidt-org/webpa-common/xmetrics"
)
const (
ListSize = "webhook_list_size_value"
NotificationUnmarshallFailed = "notification_unmarshall_failed_count"
)
type WebhookMetrics struct {
ListSize metrics.Gauge
NotificationUnmarshallFailed metrics.Counter
}
// Metrics returns the defined metrics as a list
func Metrics() []xmetrics.Metric {
return []xmetrics.Metric{
xmetrics.Metric{
Name: ListSize,
Help: "Amount of current listeners",
Type: "gauge",
},
xmetrics.Metric{
Name: NotificationUnmarshallFailed,
Help: "Count of the number notification messages that failed to unmarshall",
Type: "counter",
},
}
}
// ApplyMetricsData is used for setting the counter values on the WebhookMetrics
// when stored and accessing for later use
func ApplyMetricsData(registry xmetrics.Registry) (m WebhookMetrics) {
for _, metric := range Metrics() {
switch metric.Name {
case ListSize:
m.ListSize = registry.NewGauge(metric.Name)
m.ListSize.Add(0.0)
case NotificationUnmarshallFailed:
m.NotificationUnmarshallFailed = registry.NewCounter(metric.Name)
m.NotificationUnmarshallFailed.Add(0.0)
}
}
return
}