Skip to content

Commit 93b92d7

Browse files
cpu: parametize influxdb query
1 parent d1d8047 commit 93b92d7

File tree

1 file changed

+80
-20
lines changed

1 file changed

+80
-20
lines changed

dashboard/panels/cpu.libsonnet

Lines changed: 80 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,28 @@ local prometheus = grafana.prometheus;
9090
else if cfg.type == variable.datasource_type.influxdb then
9191
influxdb.target(
9292
rawQuery=true,
93-
query=|||
93+
// query=|||
94+
// SELECT non_negative_derivative(sum("value"), 1s)
95+
// FROM "$policy"."$measurement"
96+
// WHERE (("metric_name" = 'tnt_cpu_user_time' OR "metric_name" = 'tnt_cpu_system_time') AND "label_pairs_alias" =~ /^$alias$/)
97+
// AND $timeFilter
98+
// GROUP BY time($__interval), "label_pairs_alias" fill(none)
99+
// |||,
100+
query=std.format(|||
94101
SELECT non_negative_derivative(sum("value"), 1s)
95-
FROM "$policy"."$measurement"
96-
WHERE (("metric_name" = 'tnt_cpu_user_time' OR "metric_name" = 'tnt_cpu_system_time') AND "label_pairs_alias" =~ /^$alias$/)
102+
FROM %(measurement_with_policy)s
103+
WHERE (("metric_name" = '%(metric_user_time)s' OR "metric_name" = '%(metric_system_time)s') AND %(filters)s)
97104
AND $timeFilter
98105
GROUP BY time($__interval), "label_pairs_alias" fill(none)
99-
|||,
106+
|||, {
107+
measurement_with_policy: std.format('%(policy_prefix)s"%(measurement)s"', {
108+
policy_prefix: if cfg.policy == 'default' then '' else std.format('"%(policy)s".', cfg.policy),
109+
measurement: cfg.measurement,
110+
}),
111+
metric_user_time: cfg.metrics_prefix + 'tnt_cpu_user_time',
112+
metric_system_time: cfg.metrics_prefix + 'tnt_cpu_system_time',
113+
filters: common.influxdb_query_filters(cfg.filters),
114+
}),
100115
alias='$tag_label_pairs_alias',
101116
)
102117
),
@@ -171,13 +186,30 @@ local prometheus = grafana.prometheus;
171186
}
172187
),
173188
prometheus_legend=title,
174-
influx_query=|||
175-
SELECT non_negative_derivative(SUM("value"), 1s) AS total_cpu_time_per_cluster
176-
FROM "$policy"."$measurement"
177-
WHERE ("metric_name" = 'tnt_cpu_user_time' OR "metric_name" = 'tnt_cpu_system_time')
189+
// influx_query=|||
190+
// SELECT non_negative_derivative(SUM("value"), 1s) AS total_cpu_time_per_cluster
191+
// FROM "$policy"."$measurement"
192+
// WHERE ("metric_name" = 'tnt_cpu_user_time' OR "metric_name" = 'tnt_cpu_system_time')
193+
// AND $timeFilter
194+
// GROUP BY time($__interval)
195+
// |||,
196+
influx_query=std.format(|||
197+
SELECT non_negative_derivative(sum("value"), 1s)
198+
FROM %(measurement_with_policy)s
199+
WHERE (("metric_name" = '%(metric_user_time)s' OR "metric_name" = '%(metric_system_time)s') AND %(filters)s)
178200
AND $timeFilter
179201
GROUP BY time($__interval)
180-
|||,
202+
|||, {
203+
measurement_with_policy: std.format('%(policy_prefix)s"%(measurement)s"', {
204+
policy_prefix: if cfg.policy == 'default' then '' else std.format('"%(policy)s".', cfg.policy),
205+
measurement: cfg.measurement,
206+
}),
207+
metric_user_time: cfg.metrics_prefix + 'tnt_cpu_user_time',
208+
metric_system_time: cfg.metrics_prefix + 'tnt_cpu_system_time',
209+
filters: if common.influxdb_query_filters(common.remove_field(cfg.filters, 'label_pairs_alias')) != ''
210+
then common.influxdb_query_filters(common.remove_field(cfg.filters, 'label_pairs_alias'))
211+
else 'true',
212+
}),
181213
influx_alias=title
182214
),
183215

@@ -204,13 +236,27 @@ local prometheus = grafana.prometheus;
204236
}
205237
),
206238
prometheus_legend=title,
207-
influx_query=|||
208-
SELECT non_negative_derivative(SUM("value"), 1s) AS total_cpu_user_time
209-
FROM "$policy"."$measurement"
210-
WHERE "metric_name" = 'tnt_cpu_user_time' AND "label_pairs_alias" =~ /^$alias$/
239+
// influx_query=|||
240+
// SELECT non_negative_derivative(SUM("value"), 1s) AS total_cpu_user_time
241+
// FROM "$policy"."$measurement"
242+
// WHERE "metric_name" = 'tnt_cpu_user_time' AND "label_pairs_alias" =~ /^$alias$/
243+
// AND $timeFilter
244+
// GROUP BY time($__interval)
245+
// |||,
246+
influx_query=std.format(|||
247+
SELECT non_negative_derivative(SUM("value"), 1s)
248+
FROM %(measurement_with_policy)s
249+
WHERE "metric_name" = '%(metric_user_time)s' AND %(filters)s
211250
AND $timeFilter
212251
GROUP BY time($__interval)
213-
|||,
252+
|||, {
253+
measurement_with_policy: std.format('%(policy_prefix)s"%(measurement)s"', {
254+
policy_prefix: if cfg.policy == 'default' then '' else std.format('"%(policy)s".', cfg.policy),
255+
measurement: cfg.measurement,
256+
}),
257+
metric_user_time: cfg.metrics_prefix + 'tnt_cpu_user_time',
258+
filters: common.influxdb_query_filters(cfg.filters),
259+
}),
214260
influx_alias=title
215261
),
216262

@@ -237,13 +283,27 @@ local prometheus = grafana.prometheus;
237283
}
238284
),
239285
prometheus_legend=title,
240-
influx_query=|||
241-
SELECT non_negative_derivative(SUM("value"), 1s) AS total_cpu_system_time
242-
FROM "$policy"."$measurement"
243-
WHERE ("metric_name" = 'tnt_cpu_system_time' AND "label_pairs_alias" =~ /^$alias$/)
244-
AND $timeFilter
286+
// influx_query=|||
287+
// SELECT non_negative_derivative(SUM("value"), 1s) AS total_cpu_system_time
288+
// FROM "$policy"."$measurement"
289+
// WHERE ("metric_name" = 'tnt_cpu_system_time' AND "label_pairs_alias" =~ /^$alias$/)
290+
// AND $timeFilter
291+
// GROUP BY time($__interval)
292+
// |||,
293+
influx_query=std.format(|||
294+
SELECT non_negative_derivative(SUM("value"), 1s)
295+
FROM %(measurement_with_policy)s
296+
WHERE "metric_name" = '%(metric_system_time)s' AND %(filters)s
297+
AND $timeFilter
245298
GROUP BY time($__interval)
246-
|||,
299+
|||, {
300+
measurement_with_policy: std.format('%(policy_prefix)s"%(measurement)s"', {
301+
policy_prefix: if cfg.policy == 'default' then '' else std.format('"%(policy)s".', cfg.policy),
302+
measurement: cfg.measurement,
303+
}),
304+
metric_system_time: cfg.metrics_prefix + 'tnt_cpu_system_time',
305+
filters: common.influxdb_query_filters(cfg.filters),
306+
}),
247307
influx_alias=title
248308
),
249309

0 commit comments

Comments
 (0)