-
Notifications
You must be signed in to change notification settings - Fork 84
/
metrics.go
148 lines (139 loc) · 4.42 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
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
var metrics = struct {
lastSyncTimestamp prometheus.Gauge
ingressesTotal prometheus.Gauge
routegroupsTotal prometheus.Gauge
stacksTotal prometheus.Gauge
ownedAutoscalingGroupsTotal prometheus.Gauge
targetedAutoscalingGroupsTotal prometheus.Gauge
instancesTotal prometheus.Gauge
standaloneInstancesTotal prometheus.Gauge
certificatesTotal prometheus.Gauge
cloudWatchAlarmsTotal prometheus.Gauge
changesTotal changeCounter
}{
lastSyncTimestamp: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "last_sync_timestamp_seconds",
Help: "Timestamp of the last successful controller reconciliation run",
},
),
ingressesTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "ingresses_total",
Help: "Number of managed Kubernetes Ingresses",
},
),
routegroupsTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "routegroups_total",
Help: "Number of managed Route Groups",
},
),
stacksTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "stacks_total",
Help: "Number of managed Cloud Formation stacks",
},
),
ownedAutoscalingGroupsTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "owned_autoscaling_groups_total",
Help: "Number of owned Autoscaling Groups",
},
),
targetedAutoscalingGroupsTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "targeted_autoscaling_groups_total",
Help: "Number of targeted Autoscaling Groups",
},
),
instancesTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "instances_total",
Help: "Number of managed EC2 instances",
},
),
standaloneInstancesTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "standalone_instances_total",
Help: "Number of managed EC2 instances not in the Autoscaling Group",
},
),
certificatesTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "certificates_total",
Help: "Number of certificates",
},
),
cloudWatchAlarmsTotal: prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "cloud_watch_alarms_total",
Help: "Number of Cloud Watch Alarms",
},
),
changesTotal: changeCounter{prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "kube_ingress_aws",
Subsystem: "controller",
Name: "changes_total",
Help: "Number of Cloud Formation stack, Kubernetes Ingress and Route Group changes",
},
[]string{"resource_type", "operation"},
)},
}
type changeCounter struct {
*prometheus.CounterVec
}
func (c changeCounter) created(resourceType string) {
c.WithLabelValues(resourceType, "create").Inc()
}
func (c changeCounter) updated(resourceType string) {
c.WithLabelValues(resourceType, "update").Inc()
}
func (c changeCounter) deleted(resourceType string) {
c.WithLabelValues(resourceType, "delete").Inc()
}
func registerMetrics() {
prometheus.MustRegister(metrics.lastSyncTimestamp)
prometheus.MustRegister(metrics.ingressesTotal)
prometheus.MustRegister(metrics.routegroupsTotal)
prometheus.MustRegister(metrics.stacksTotal)
prometheus.MustRegister(metrics.ownedAutoscalingGroupsTotal)
prometheus.MustRegister(metrics.targetedAutoscalingGroupsTotal)
prometheus.MustRegister(metrics.instancesTotal)
prometheus.MustRegister(metrics.standaloneInstancesTotal)
prometheus.MustRegister(metrics.certificatesTotal)
prometheus.MustRegister(metrics.cloudWatchAlarmsTotal)
prometheus.MustRegister(metrics.changesTotal)
}
func serveMetrics(address string) {
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(address, nil))
}