Skip to content

Commit 2dbe4f9

Browse files
authored
Merge pull request #824 from TBurda/master
fix multi-cluster support for windows
2 parents bcf8426 + 231729d commit 2dbe4f9

File tree

2 files changed

+62
-59
lines changed

2 files changed

+62
-59
lines changed

dashboards/windows.libsonnet

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,22 @@ local g = import 'github.com/grafana/jsonnet-libs/grafana-builder/grafana.libson
165165
)
166166
.addTemplate(
167167
template.new(
168-
'namespace',
168+
'cluster',
169169
'$datasource',
170-
'label_values(windows_pod_container_available, namespace)',
171-
label='Namespace',
170+
'label_values(up{%(windowsExporterSelector)s}, %(clusterLabel)s)' % $._config,
171+
label='cluster',
172172
refresh='time',
173+
hide=if $._config.showMultiCluster then '' else 'variable',
173174
sort=1,
174175
)
175-
).addTemplate(
176+
)
177+
.addTemplate(
176178
template.new(
177-
'cluster',
179+
'namespace',
178180
'$datasource',
179-
'label_values(up{%(windowsExporterSelector)s}, %(clusterLabel)s)' % $._config,
180-
label='cluster',
181+
'label_values(windows_pod_container_available{%(clusterLabel)s="$cluster"}, namespace)' % $._config,
182+
label='Namespace',
181183
refresh='time',
182-
hide=if $._config.showMultiCluster then '' else 'variable',
183184
sort=1,
184185
)
185186
)
@@ -268,31 +269,32 @@ local g = import 'github.com/grafana/jsonnet-libs/grafana-builder/grafana.libson
268269
)
269270
.addTemplate(
270271
template.new(
271-
'namespace',
272+
'cluster',
272273
'$datasource',
273-
'label_values(windows_pod_container_available, namespace)',
274-
label='Namespace',
274+
'label_values(up{%(windowsExporterSelector)s}, %(clusterLabel)s)' % $._config,
275+
label='cluster',
275276
refresh='time',
277+
hide=if $._config.showMultiCluster then '' else 'variable',
276278
sort=1,
277279
)
278280
)
279281
.addTemplate(
280282
template.new(
281-
'pod',
283+
'namespace',
282284
'$datasource',
283-
'label_values(windows_pod_container_available{namespace="$namespace"}, pod)',
284-
label='Pod',
285+
'label_values(windows_pod_container_available{%(clusterLabel)s="$cluster"}, namespace)' % $._config,
286+
label='Namespace',
285287
refresh='time',
286288
sort=1,
287289
)
288-
).addTemplate(
290+
)
291+
.addTemplate(
289292
template.new(
290-
'cluster',
293+
'pod',
291294
'$datasource',
292-
'label_values(up{%(windowsExporterSelector)s}, %(clusterLabel)s)' % $._config,
293-
label='cluster',
295+
'label_values(windows_pod_container_available{%(clusterLabel)s="$cluster",namespace="$namespace"}, pod)' % $._config,
296+
label='Pod',
294297
refresh='time',
295-
hide=if $._config.showMultiCluster then '' else 'variable',
296298
sort=1,
297299
)
298300
)
@@ -494,21 +496,22 @@ local g = import 'github.com/grafana/jsonnet-libs/grafana-builder/grafana.libson
494496
)
495497
.addTemplate(
496498
template.new(
497-
'instance',
499+
'cluster',
498500
'$datasource',
499-
'label_values(windows_system_system_up_time, instance)',
500-
label='Instance',
501+
'label_values(up{%(windowsExporterSelector)s}, %(clusterLabel)s)' % $._config,
502+
label='cluster',
501503
refresh='time',
504+
hide=if $._config.showMultiCluster then '' else 'variable',
502505
sort=1,
503506
)
504-
).addTemplate(
507+
)
508+
.addTemplate(
505509
template.new(
506-
'cluster',
510+
'instance',
507511
'$datasource',
508-
'label_values(up{%(windowsExporterSelector)s}, %(clusterLabel)s)' % $._config,
509-
label='cluster',
512+
'label_values(windows_system_system_up_time{%(clusterLabel)s="$cluster"}, instance)' % $._config,
513+
label='Instance',
510514
refresh='time',
511-
hide=if $._config.showMultiCluster then '' else 'variable',
512515
sort=1,
513516
)
514517
)

rules/windows.libsonnet

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// This rule gives the number of windows nodes
99
record: 'node:windows_node:sum',
1010
expr: |||
11-
count (
11+
count by (%(clusterLabel)s) (
1212
windows_system_system_up_time{%(windowsExporterSelector)s}
1313
)
1414
||| % $._config,
@@ -17,7 +17,7 @@
1717
// This rule gives the number of CPUs per node.
1818
record: 'node:windows_node_num_cpu:sum',
1919
expr: |||
20-
count by (instance) (sum by (instance, core) (
20+
count by (%(clusterLabel)s, instance) (sum by (%(clusterLabel)s, instance, core) (
2121
windows_cpu_time_total{%(windowsExporterSelector)s}
2222
))
2323
||| % $._config,
@@ -26,14 +26,14 @@
2626
// CPU utilisation is % CPU is not idle.
2727
record: ':windows_node_cpu_utilisation:avg1m',
2828
expr: |||
29-
1 - avg(rate(windows_cpu_time_total{%(windowsExporterSelector)s,mode="idle"}[1m]))
29+
1 - avg by (%(clusterLabel)s) (rate(windows_cpu_time_total{%(windowsExporterSelector)s,mode="idle"}[1m]))
3030
||| % $._config,
3131
},
3232
{
3333
// CPU utilisation is % CPU is not idle.
3434
record: 'node:windows_node_cpu_utilisation:avg1m',
3535
expr: |||
36-
1 - avg by (instance) (
36+
1 - avg by (%(clusterLabel)s, instance) (
3737
rate(windows_cpu_time_total{%(windowsExporterSelector)s,mode="idle"}[1m])
3838
)
3939
||| % $._config,
@@ -42,17 +42,17 @@
4242
record: ':windows_node_memory_utilisation:',
4343
expr: |||
4444
1 -
45-
sum(windows_memory_available_bytes{%(windowsExporterSelector)s})
45+
sum by (%(clusterLabel)s) (windows_memory_available_bytes{%(windowsExporterSelector)s})
4646
/
47-
sum(windows_os_visible_memory_bytes{%(windowsExporterSelector)s})
47+
sum by (%(clusterLabel)s) (windows_os_visible_memory_bytes{%(windowsExporterSelector)s})
4848
||| % $._config,
4949
},
5050
// Add separate rules for Free & Total, so we can aggregate across clusters
5151
// in dashboards.
5252
{
5353
record: ':windows_node_memory_MemFreeCached_bytes:sum',
5454
expr: |||
55-
sum(windows_memory_available_bytes{%(windowsExporterSelector)s} + windows_memory_cache_bytes{%(windowsExporterSelector)s})
55+
sum by (%(clusterLabel)s) (windows_memory_available_bytes{%(windowsExporterSelector)s} + windows_memory_cache_bytes{%(windowsExporterSelector)s})
5656
||| % $._config,
5757
},
5858
{
@@ -64,15 +64,15 @@
6464
{
6565
record: ':windows_node_memory_MemTotal_bytes:sum',
6666
expr: |||
67-
sum(windows_os_visible_memory_bytes{%(windowsExporterSelector)s})
67+
sum by (%(clusterLabel)s) (windows_os_visible_memory_bytes{%(windowsExporterSelector)s})
6868
||| % $._config,
6969
},
7070
{
7171
// Available memory per node
7272
// SINCE 2018-02-08
7373
record: 'node:windows_node_memory_bytes_available:sum',
7474
expr: |||
75-
sum by (instance) (
75+
sum by (%(clusterLabel)s, instance) (
7676
(windows_memory_available_bytes{%(windowsExporterSelector)s})
7777
)
7878
||| % $._config,
@@ -81,7 +81,7 @@
8181
// Total memory per node
8282
record: 'node:windows_node_memory_bytes_total:sum',
8383
expr: |||
84-
sum by (instance) (
84+
sum by (%(clusterLabel)s, instance) (
8585
windows_os_visible_memory_bytes{%(windowsExporterSelector)s}
8686
)
8787
||| % $._config,
@@ -111,7 +111,7 @@
111111
// Disk utilisation (ms spent, by rate() it's bound by 1 second)
112112
record: ':windows_node_disk_utilisation:avg_irate',
113113
expr: |||
114-
avg(irate(windows_logical_disk_read_seconds_total{%(windowsExporterSelector)s}[1m]) +
114+
avg by (%(clusterLabel)s) (irate(windows_logical_disk_read_seconds_total{%(windowsExporterSelector)s}[1m]) +
115115
irate(windows_logical_disk_write_seconds_total{%(windowsExporterSelector)s}[1m])
116116
)
117117
||| % $._config,
@@ -120,7 +120,7 @@
120120
// Disk utilisation (ms spent, by rate() it's bound by 1 second)
121121
record: 'node:windows_node_disk_utilisation:avg_irate',
122122
expr: |||
123-
avg by (instance) (
123+
avg by (%(clusterLabel)s, instance) (
124124
(irate(windows_logical_disk_read_seconds_total{%(windowsExporterSelector)s}[1m]) +
125125
irate(windows_logical_disk_write_seconds_total{%(windowsExporterSelector)s}[1m]))
126126
)
@@ -129,7 +129,7 @@
129129
{
130130
record: 'node:windows_node_filesystem_usage:',
131131
expr: |||
132-
max by (instance,volume)(
132+
max by (%(clusterLabel)s,instance,volume)(
133133
(windows_logical_disk_size_bytes{%(windowsExporterSelector)s}
134134
- windows_logical_disk_free_bytes{%(windowsExporterSelector)s})
135135
/ windows_logical_disk_size_bytes{%(windowsExporterSelector)s}
@@ -139,34 +139,34 @@
139139
{
140140
record: 'node:windows_node_filesystem_avail:',
141141
expr: |||
142-
max by (instance, volume) (windows_logical_disk_free_bytes{%(windowsExporterSelector)s} / windows_logical_disk_size_bytes{%(windowsExporterSelector)s})
142+
max by (%(clusterLabel)s, instance, volume) (windows_logical_disk_free_bytes{%(windowsExporterSelector)s} / windows_logical_disk_size_bytes{%(windowsExporterSelector)s})
143143
||| % $._config,
144144
},
145145
{
146146
record: ':windows_node_net_utilisation:sum_irate',
147147
expr: |||
148-
sum(irate(windows_net_bytes_total{%(windowsExporterSelector)s}[1m]))
148+
sum by (%(clusterLabel)s) (irate(windows_net_bytes_total{%(windowsExporterSelector)s}[1m]))
149149
||| % $._config,
150150
},
151151
{
152152
record: 'node:windows_node_net_utilisation:sum_irate',
153153
expr: |||
154-
sum by (instance) (
154+
sum by (%(clusterLabel)s, instance) (
155155
(irate(windows_net_bytes_total{%(windowsExporterSelector)s}[1m]))
156156
)
157157
||| % $._config,
158158
},
159159
{
160160
record: ':windows_node_net_saturation:sum_irate',
161161
expr: |||
162-
sum(irate(windows_net_packets_received_discarded_total{%(windowsExporterSelector)s}[1m])) +
163-
sum(irate(windows_net_packets_outbound_discarded_total{%(windowsExporterSelector)s}[1m]))
162+
sum by (%(clusterLabel)s) (irate(windows_net_packets_received_discarded_total{%(windowsExporterSelector)s}[1m])) +
163+
sum by (%(clusterLabel)s) (irate(windows_net_packets_outbound_discarded_total{%(windowsExporterSelector)s}[1m]))
164164
||| % $._config,
165165
},
166166
{
167167
record: 'node:windows_node_net_saturation:sum_irate',
168168
expr: |||
169-
sum by (instance) (
169+
sum by (%(clusterLabel)s, instance) (
170170
(irate(windows_net_packets_received_discarded_total{%(windowsExporterSelector)s}[1m]) +
171171
irate(windows_net_packets_outbound_discarded_total{%(windowsExporterSelector)s}[1m]))
172172
)
@@ -180,71 +180,71 @@
180180
{
181181
record: 'windows_pod_container_available',
182182
expr: |||
183-
windows_container_available{%(windowsExporterSelector)s, container_id != ""} * on(container_id) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace)
183+
windows_container_available{%(windowsExporterSelector)s, container_id != ""} * on(container_id, %(clusterLabel)s) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace, %(clusterLabel)s)
184184
||| % $._config,
185185
},
186186
{
187187
record: 'windows_container_total_runtime',
188188
expr: |||
189-
windows_container_cpu_usage_seconds_total{%(windowsExporterSelector)s, container_id != ""} * on(container_id) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace)
189+
windows_container_cpu_usage_seconds_total{%(windowsExporterSelector)s, container_id != ""} * on(container_id, %(clusterLabel)s) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace, %(clusterLabel)s)
190190
||| % $._config,
191191
},
192192
{
193193
record: 'windows_container_memory_usage',
194194
expr: |||
195-
windows_container_memory_usage_commit_bytes{%(windowsExporterSelector)s, container_id != ""} * on(container_id) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace)
195+
windows_container_memory_usage_commit_bytes{%(windowsExporterSelector)s, container_id != ""} * on(container_id, %(clusterLabel)s) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace, %(clusterLabel)s)
196196
||| % $._config,
197197
},
198198
{
199199
record: 'windows_container_private_working_set_usage',
200200
expr: |||
201-
windows_container_memory_usage_private_working_set_bytes{%(windowsExporterSelector)s, container_id != ""} * on(container_id) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace)
201+
windows_container_memory_usage_private_working_set_bytes{%(windowsExporterSelector)s, container_id != ""} * on(container_id, %(clusterLabel)s) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace, %(clusterLabel)s)
202202
||| % $._config,
203203
},
204204
{
205205
record: 'windows_container_network_received_bytes_total',
206206
expr: |||
207-
windows_container_network_receive_bytes_total{%(windowsExporterSelector)s, container_id != ""} * on(container_id) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace)
207+
windows_container_network_receive_bytes_total{%(windowsExporterSelector)s, container_id != ""} * on(container_id, %(clusterLabel)s) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace, %(clusterLabel)s)
208208
||| % $._config,
209209
},
210210
{
211211
record: 'windows_container_network_transmitted_bytes_total',
212212
expr: |||
213-
windows_container_network_transmit_bytes_total{%(windowsExporterSelector)s, container_id != ""} * on(container_id) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace)
213+
windows_container_network_transmit_bytes_total{%(windowsExporterSelector)s, container_id != ""} * on(container_id, %(clusterLabel)s) group_left(container, pod, namespace) max(kube_pod_container_info{%(kubeStateMetricsSelector)s, container_id != ""}) by(container, container_id, pod, namespace, %(clusterLabel)s)
214214
||| % $._config,
215215
},
216216
{
217217
record: 'kube_pod_windows_container_resource_memory_request',
218218
expr: |||
219-
max by (namespace, pod, container) (
219+
max by (%(clusterLabel)s, namespace, pod, container) (
220220
kube_pod_container_resource_requests{resource="memory",%(kubeStateMetricsSelector)s}
221-
) * on(container,pod,namespace) (windows_pod_container_available)
221+
) * on(container,pod,namespace,%(clusterLabel)s) (windows_pod_container_available)
222222
||| % $._config,
223223
},
224224
{
225225
record: 'kube_pod_windows_container_resource_memory_limit',
226226
expr: |||
227-
kube_pod_container_resource_limits{resource="memory",%(kubeStateMetricsSelector)s} * on(container,pod,namespace) (windows_pod_container_available)
227+
kube_pod_container_resource_limits{resource="memory",%(kubeStateMetricsSelector)s} * on(container,pod,namespace,%(clusterLabel)s) (windows_pod_container_available)
228228
||| % $._config,
229229
},
230230
{
231231
record: 'kube_pod_windows_container_resource_cpu_cores_request',
232232
expr: |||
233-
max by (namespace, pod, container) (
233+
max by (%(clusterLabel)s, namespace, pod, container) (
234234
kube_pod_container_resource_requests{resource="cpu",%(kubeStateMetricsSelector)s}
235-
) * on(container,pod,namespace) (windows_pod_container_available)
235+
) * on(container,pod,namespace,%(clusterLabel)s) (windows_pod_container_available)
236236
||| % $._config,
237237
},
238238
{
239239
record: 'kube_pod_windows_container_resource_cpu_cores_limit',
240240
expr: |||
241-
kube_pod_container_resource_limits{resource="cpu",%(kubeStateMetricsSelector)s} * on(container,pod,namespace) (windows_pod_container_available)
241+
kube_pod_container_resource_limits{resource="cpu",%(kubeStateMetricsSelector)s} * on(container,pod,namespace,%(clusterLabel)s) (windows_pod_container_available)
242242
||| % $._config,
243243
},
244244
{
245245
record: 'namespace_pod_container:windows_container_cpu_usage_seconds_total:sum_rate',
246246
expr: |||
247-
sum by (namespace, pod, container) (
247+
sum by (%(clusterLabel)s, namespace, pod, container) (
248248
rate(windows_container_total_runtime{}[5m])
249249
)
250250
||| % $._config,

0 commit comments

Comments
 (0)