/
metrics.go
69 lines (61 loc) · 1.71 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
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
StsConnectionFailure prometheus.Counter
StsResponseError prometheus.Counter
Latency *prometheus.HistogramVec
}
func createMetrics(reg prometheus.Registerer) Metrics {
factory := promauto.With(reg)
return Metrics{
ConfigMapWatchFailures: factory.NewCounter(
prometheus.CounterOpts{
Namespace: Namespace,
Name: "configmap_watch_failures",
Help: "EKS Configmap watch failures",
},
),
StsConnectionFailure: factory.NewCounter(
prometheus.CounterOpts{
Namespace: Namespace,
Name: "sts_connection_failures",
Help: "Sts call could not succeed or timedout",
},
),
StsResponseError: factory.NewCounter(
prometheus.CounterOpts{
Namespace: Namespace,
Name: "sts_response_error_code_not_200",
Help: "Sts response error code is not 2xx",
},
),
Latency: factory.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: Namespace,
Name: "authenticate_latency_seconds",
Help: "Authenticate call latency",
},
[]string{"result"},
),
}
}