/
metrics.go
77 lines (69 loc) · 2.04 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
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
const (
Namespace = "aws_iam_authenticator"
Malformed = "malformed_request"
Invalid = "invalid_token"
STSError = "sts_error"
Unknown = "uknown_user"
Success = "success"
)
var authenticatorMetrics Metrics
func InitMetrics(registerer prometheus.Registerer) {
authenticatorMetrics = createMetrics(registerer)
}
func Get() Metrics {
return authenticatorMetrics
}
// Metrics are handles to the collectors for prometheus for the various metrics we are tracking.
type Metrics struct {
ConfigMapWatchFailures prometheus.Counter
EC2DescribeInstanceCallCount prometheus.Counter
Latency *prometheus.HistogramVec
StsConnectionFailure prometheus.Counter
StsResponses *prometheus.CounterVec
}
func createMetrics(reg prometheus.Registerer) Metrics {
factory := promauto.With(reg)
return Metrics{
ConfigMapWatchFailures: factory.NewCounter(
prometheus.CounterOpts{
Namespace: Namespace,
Name: "configmap_watch_failures_total",
Help: "EKS Configmap watch failures",
},
),
StsConnectionFailure: factory.NewCounter(
prometheus.CounterOpts{
Namespace: Namespace,
Name: "sts_connection_failures_total",
Help: "Sts call could not succeed or timedout",
},
),
StsResponses: factory.NewCounterVec(
prometheus.CounterOpts{
Namespace: Namespace,
Name: "sts_responses_total",
Help: "Sts responses with error code label",
}, []string{"ResponseCode"},
),
Latency: factory.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: Namespace,
Name: "authenticate_latency_seconds",
Help: "Authenticate call latency",
},
[]string{"result"},
),
EC2DescribeInstanceCallCount: factory.NewCounter(
prometheus.CounterOpts{
Namespace: Namespace,
Name: "ec2_describe_instances_calls_total",
Help: "Number of EC2 describe instances calls.",
},
),
}
}