-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmetrics.go
More file actions
188 lines (181 loc) · 7.61 KB
/
Copy pathmetrics.go
File metadata and controls
188 lines (181 loc) · 7.61 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package controller
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"sigs.k8s.io/controller-runtime/pkg/metrics"
)
const (
METIC_PREFIX = "node_disruption_controller_"
NodeDisruptionReconcileController = "NodeDisruption"
ReconcileResultSuccess = "success"
ReconcileResultError = "error"
)
var (
// NODE DISRUPTION METRICS
NodeDisruptionReconcileTotal = promauto.With(metrics.Registry).NewCounterVec(
prometheus.CounterOpts{
Name: METIC_PREFIX + "reconcile_total",
Help: "Total number of node disruption controller reconciliations by result",
},
[]string{"controller", "result"},
)
NodeDisruptionLastSuccessfulReconcileTimestamp = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "last_successful_reconcile_timestamp_seconds",
Help: "Unix timestamp of the last successful node disruption controller reconciliation",
},
[]string{"controller"},
)
NodeDisruptionLastFailedReconcileTimestamp = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "last_failed_reconcile_timestamp_seconds",
Help: "Unix timestamp of the last failed node disruption controller reconciliation",
},
[]string{"controller"},
)
NodeDisruptionGrantedTotal = promauto.With(metrics.Registry).NewCounterVec(
prometheus.CounterOpts{
Name: METIC_PREFIX + "node_disruption_granted_total",
Help: "Total number of granted node disruptions",
},
[]string{"type"},
)
NodeDisruptionRejectedTotal = promauto.With(metrics.Registry).NewCounterVec(
prometheus.CounterOpts{
Name: METIC_PREFIX + "node_disruption_rejected_total",
Help: "Total number of rejected node disruptions",
},
[]string{"type"},
)
NodeDisruptionStateAsValue = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "node_disruption_state_value",
Help: "State of node disruption: pending=0, rejected=-1, accepted=1",
},
[]string{"node_disruption_name", "type"},
)
NodeDisruptionStateAsLabel = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "node_disruption_state_label",
Help: "State of node disruption: 0 not in this state; 1 is in state",
},
[]string{"node_disruption_name", "state", "type"},
)
NodeDisruptionCreated = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "node_disruption_created",
Help: "Date of create of the node disruption",
},
[]string{"node_disruption_name", "type"},
)
NodeDisruptionDeadline = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "node_disruption_deadline",
Help: "Date of the deadline of the node disruption (0 if unset)",
},
[]string{"node_disruption_name", "type"},
)
NodeDisruptionImpactedNodes = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "node_disruption_impacted_node",
Help: "high cardinality: create a metric for each node impacted by a given node disruption",
},
[]string{"node_disruption_name", "node_name", "type"},
)
NodeDisruptionType = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "node_disruption_type",
Help: "Type of the node disruption",
},
[]string{"node_disruption_name", "type"},
)
// DISRUPTION BUDGET METRICS
DisruptionBudgetCheckHealthHookStatusCodeTotal = promauto.With(metrics.Registry).NewCounterVec(
prometheus.CounterOpts{
Name: METIC_PREFIX + "disruption_budget_health_hook_status_code_total",
Help: "Total number of request by HTTP status code",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind", "status_code"},
)
DisruptionBudgetCheckHealthHookErrorTotal = promauto.With(metrics.Registry).NewCounterVec(
prometheus.CounterOpts{
Name: METIC_PREFIX + "disruption_budget_health_hook_error_total",
Help: "Total number of connection/response errors while requesting health hook",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind"},
)
DisruptionBudgetRejectedTotal = promauto.With(metrics.Registry).NewCounterVec(
prometheus.CounterOpts{
Name: METIC_PREFIX + "disruption_budget_rejected_total",
Help: "Total number of rejected node disruption by the disruption budget",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind"},
)
DisruptionBudgetGrantedTotal = promauto.With(metrics.Registry).NewCounterVec(
prometheus.CounterOpts{
Name: METIC_PREFIX + "disruption_budget_granted_total",
Help: "Total number of granted node disruption by the disruption budget",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind"},
)
DisruptionBudgetMaxDisruptions = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "disruption_budget_max_disruptions",
Help: "Reflect the MaxDisruptions fields from budget Spec",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind"},
)
DisruptionBudgetCurrentDisruptions = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "disruption_budget_current_disruptions",
Help: "Reflect the CurrentDisruptions fields from budget Status",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind"},
)
DisruptionBudgetDisruptionsAllowed = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "disruption_budget_disruptions_allowed",
Help: "Reflect the DisruptionsAllowed fields from budget Status",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind"},
)
DisruptionBudgetMaxDisruptedNodes = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "disruption_budget_max_disrupted_nodes",
Help: "Reflect the MaxDisruptedNodes fields from budget Spec",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind"},
)
DisruptionBudgetMinUndisruptedNodes = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "disruption_budget_min_undisrupted_nodes",
Help: "Reflect the MinUndisruptedNodes fields from budget Spec",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind"},
)
DisruptionBudgetWatchedNodes = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "node_disruption_watched_nodes",
Help: "high cardinality: create a metric for each node watched by a budget",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind", "node_name"},
)
DisruptionBudgetDisruptions = promauto.With(metrics.Registry).NewGaugeVec(
prometheus.GaugeOpts{
Name: METIC_PREFIX + "budget_disruption_disruptions",
Help: "high cardinality: create a metric for each disruption by a budget",
},
[]string{"disruption_budget_namespace", "disruption_budget_name", "disruption_budget_kind", "node_disruption_name"},
)
)
func ObserveNodeDisruptionReconcile(result string) {
NodeDisruptionReconcileTotal.WithLabelValues(NodeDisruptionReconcileController, result).Inc()
now := float64(time.Now().Unix())
switch result {
case ReconcileResultSuccess:
NodeDisruptionLastSuccessfulReconcileTimestamp.WithLabelValues(NodeDisruptionReconcileController).Set(now)
case ReconcileResultError:
NodeDisruptionLastFailedReconcileTimestamp.WithLabelValues(NodeDisruptionReconcileController).Set(now)
}
}