From 5abf084fc16f57a70beb50802bc7418009ae4c51 Mon Sep 17 00:00:00 2001 From: Vitaly Zhuravlev Date: Wed, 11 May 2022 18:54:29 +0400 Subject: [PATCH] use template from grafonnet library --- .../dashboards/apache-exporter-full.libsonnet | 58 ++++++++++++------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/prometheus/apache-http-mixin/dashboards/apache-exporter-full.libsonnet b/prometheus/apache-http-mixin/dashboards/apache-exporter-full.libsonnet index 82696e8..10178dd 100644 --- a/prometheus/apache-http-mixin/dashboards/apache-exporter-full.libsonnet +++ b/prometheus/apache-http-mixin/dashboards/apache-exporter-full.libsonnet @@ -1,8 +1,26 @@ local grafana = import 'github.com/grafana/grafonnet-lib/grafonnet/grafana.libsonnet'; local dashboard = grafana.dashboard; +local template = grafana.template; + { grafanaDashboards+:: { + + local apacheClusterSelectorTemplates = + [ + template.new( + name=label, + label=label, + datasource='$datasource', + query='label_values(apache_up, %s)' % label, + current='', + refresh=2, + includeAll=false, + sort=1 + ) + for label in std.split($._config.apacheClusterLabels, ',') + ], + 'apache-http.json': dashboard.new( 'Apache HTTP server', @@ -22,31 +40,31 @@ local dashboard = grafana.dashboard; hide: 0, label: 'Data Source', name: 'datasource', - options: [], query: 'prometheus', refresh: 1, regex: '', type: 'datasource', }, - { - allValue: null, - current: {}, - datasource: '${datasource}', - hide: 0, - includeAll: false, - label: 'instance', - multi: false, - name: 'instance', - options: [], - query: 'label_values(apache_up, instance)', - refresh: 2, - sort: 1, - tagValuesQuery: '', - tags: [], - tagsQuery: '', - type: 'query', - useTags: false, - }, + template.new( + name='job', + label='job', + datasource='$datasource', + query='label_values(apache_up, job)', + current='', + refresh=2, + includeAll=true, + sort=1 + ), + template.new( + name='instance', + label='instance', + datasource='$datasource', + query='label_values(apache_up{job=~"$job"}, instance)', + current='', + refresh=2, + includeAll=false, + sort=1 + ), ] ) .addPanels([