/
metrics.go
135 lines (127 loc) · 3.85 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package aws
import (
"github.com/go-kit/kit/metrics"
"github.com/prometheus/client_golang/prometheus"
themisXmetrics "github.com/xmidt-org/themis/xmetrics"
"github.com/xmidt-org/webpa-common/xmetrics"
"go.uber.org/fx"
)
const (
DnsReadyQueryCount = "dns_ready_query_count"
DnsReady = "dns_ready"
SNSNotificationReceived = "webhook_sns_notification_received_count"
SNSNotificationSent = "webhook_sns_notification_sent_count"
SNSSubscribeAttempt = "webhook_sns_subscribe_attempt_count"
SNSSubscribed = "webhook_sns_subscribed_value"
)
type AWSMetrics struct {
fx.In
DnsReadyQueryCount metrics.Counter `name:"dns_ready_query_count"`
DnsReady metrics.Gauge `name:"dns_ready"`
SNSNotificationReceived metrics.Counter `name:"webhook_sns_notification_received_count"`
SNSNotificationSent metrics.Counter `name:"webhook_sns_notification_sent_count"`
SNSSubscribeAttempt metrics.Counter `name:"webhook_sns_subscribe_attempt_count"`
SNSSubscribed metrics.Gauge `name:"webhook_sns_subscribed_value"`
}
func ProvideMetrics() fx.Option {
return fx.Provide(
themisXmetrics.ProvideCounter(
prometheus.CounterOpts{
Name: DnsReadyQueryCount,
Help: "Count of the number of queries made checking if DNS is ready",
},
),
themisXmetrics.ProvideGauge(
prometheus.GaugeOpts{
Name: DnsReady,
Help: "Is the DNS ready",
},
),
themisXmetrics.ProvideCounter(
prometheus.CounterOpts{
Name: SNSNotificationReceived,
Help: "Count of the number SNS notifications received",
}, "code",
),
themisXmetrics.ProvideCounter(
prometheus.CounterOpts{
Name: SNSNotificationSent,
Help: "Count of the number SNS notifications received",
},
),
themisXmetrics.ProvideCounter(
prometheus.CounterOpts{
Name: SNSSubscribeAttempt,
Help: "Count of the number of SNS subscription attempts",
}, "code",
),
themisXmetrics.ProvideGauge(
prometheus.GaugeOpts{
Name: SNSSubscribed,
Help: "Is this instance subscribed to SNS",
},
),
)
}
// Metrics returns the defined metrics as a list
func Metrics() []xmetrics.Metric {
return []xmetrics.Metric{
xmetrics.Metric{
Name: DnsReadyQueryCount,
Help: "Count of the number of queries made checking if DNS is ready",
Type: "counter",
},
xmetrics.Metric{
Name: DnsReady,
Help: "Is the DNS ready",
Type: "gauge",
},
xmetrics.Metric{
Name: SNSNotificationReceived,
Help: "Count of the number SNS notifications received",
Type: "counter",
LabelNames: []string{"code"},
},
xmetrics.Metric{
Name: SNSNotificationSent,
Help: "Count of the number SNS notifications received",
Type: "counter",
},
xmetrics.Metric{
Name: SNSSubscribeAttempt,
Help: "Count of the number of SNS subscription attempts",
Type: "counter",
LabelNames: []string{"code"},
},
xmetrics.Metric{
Name: SNSSubscribed,
Help: "Is this instance subscribed to SNS",
Type: "gauge",
},
}
}
// ApplyMetricsData is used for setting the counter values on the AWSMetrics
// when stored and accessing for later use
func ApplyMetricsData(registry xmetrics.Registry) (m AWSMetrics) {
for _, metric := range Metrics() {
switch metric.Name {
case DnsReadyQueryCount:
m.DnsReadyQueryCount = registry.NewCounter(metric.Name)
m.DnsReadyQueryCount.Add(0.0)
case DnsReady:
m.DnsReady = registry.NewGauge(metric.Name)
m.DnsReady.Add(0.0)
case SNSNotificationReceived:
m.SNSNotificationReceived = registry.NewCounter(metric.Name)
case SNSNotificationSent:
m.SNSNotificationSent = registry.NewCounter(metric.Name)
m.SNSNotificationSent.Add(0.0)
case SNSSubscribeAttempt:
m.SNSSubscribeAttempt = registry.NewCounter(metric.Name)
case SNSSubscribed:
m.SNSSubscribed = registry.NewGauge(metric.Name)
m.SNSSubscribed.Add(0.0)
}
}
return
}