Skip to content

Commit bbb57cc

Browse files
dashboard: set Prometheus job dynamically
After this patch, user may choose Prometheus job from the list of jobs with Tarantool metrics instead of manually setting up a constant job on import. Part of #185
1 parent f49d0a0 commit bbb57cc

File tree

11 files changed

+59
-97
lines changed

11 files changed

+59
-97
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Changed
1010
- Replace LuaJit deprecated metrics with new ones
11+
- Set Prometheus `job` dynamically
1112

1213

1314
## [1.5.0] - 2022-09-22

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ Refer to dashboard [documentation page](https://www.tarantool.io/en/doc/latest/b
4949
- `Measurement`,
5050
- `Policy` (default valie is `autogen`).
5151

52-
You need to set the following variables for Prometheus datasource:
53-
54-
- `Job`.
55-
5652
Datasource variables can be obtained from your datasource configuration.
53+
You can choose `job` variable value for Prometheus datasource after import.
5754
Variables for example monitoring cluster are described in [Monitoring cluster](#monitoring-cluster) section.
5855

5956

@@ -78,10 +75,6 @@ To set up an InfluxDB dashboard for monitoring example app, use the following va
7875
- `Measurement`: `tarantool_http`;
7976
- `Policy`: `default`.
8077

81-
To set up an Prometheus dashboard for monitoring example app, use the following variables:
82-
83-
- `Job`: `tarantool`.
84-
8578
### Monitoring local app
8679

8780
If you want to monitor Tarantool cluster deployed on your local host, you can use monitoring cluster similar to example app one.

dashboard/build/prometheus/dashboard.libsonnet

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,19 @@ dashboard_raw(
1414
pluginId='prometheus',
1515
pluginName='Prometheus',
1616
description='Prometheus Tarantool metrics bank'
17-
).addInput(
18-
name='PROMETHEUS_JOB',
19-
label='Job',
20-
type='constant',
21-
value='tarantool',
22-
description='Prometheus Tarantool metrics job'
2317
).addTemplate(
24-
grafana.template.custom(
18+
grafana.template.new(
2519
name='job',
26-
query='${PROMETHEUS_JOB}',
27-
current='${PROMETHEUS_JOB}',
28-
hide='variable',
20+
datasource=variable.datasource.prometheus,
21+
query=std.format('label_values(%s,job)', variable.metrics.tarantool_indicator),
2922
label='Prometheus job',
23+
refresh='load',
3024
)
3125
).addTemplate(
3226
grafana.template.new(
3327
name='alias',
3428
datasource=variable.datasource.prometheus,
35-
query=std.format('label_values(tnt_info_uptime{job=~"%s"},alias)', variable.prometheus.job),
29+
query=std.format('label_values(%s{job=~"%s"},alias)', [variable.metrics.tarantool_indicator, variable.prometheus.job]),
3630
includeAll=true,
3731
multi=true,
3832
current='all',

dashboard/build/prometheus/dashboard_static.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if WITH_INSTANCE_VARIABLE then
1616
grafana.template.new(
1717
name='alias',
1818
datasource=DATASOURCE,
19-
query=std.format('label_values(tnt_info_uptime{job="%s"},alias)', JOB),
19+
query=std.format('label_values(%s{job="%s"},alias)', [variable.metrics.tarantool_indicator, JOB]),
2020
includeAll=true,
2121
multi=true,
2222
current='all',

dashboard/build/prometheus/tdg_dashboard.libsonnet

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,19 @@ tdg_dashboard_raw(
1414
pluginId='prometheus',
1515
pluginName='Prometheus',
1616
description='Prometheus Tarantool metrics bank'
17-
).addInput(
18-
name='PROMETHEUS_JOB',
19-
label='Job',
20-
type='constant',
21-
value='tarantool',
22-
description='Prometheus Tarantool metrics job'
2317
).addTemplate(
24-
grafana.template.custom(
18+
grafana.template.new(
2519
name='job',
26-
query='${PROMETHEUS_JOB}',
27-
current='${PROMETHEUS_JOB}',
28-
hide='variable',
20+
datasource=variable.datasource.prometheus,
21+
query=std.format('label_values(%s,job)', variable.metrics.tarantool_indicator),
2922
label='Prometheus job',
23+
refresh='load',
3024
)
3125
).addTemplate(
3226
grafana.template.new(
3327
name='alias',
3428
datasource=variable.datasource.prometheus,
35-
query='label_values(tnt_info_uptime{job=~"$job"},alias)',
29+
query=std.format('label_values(%s{job=~"%s"},alias)', [variable.metrics.tarantool_indicator, variable.prometheus.job]),
3630
includeAll=true,
3731
multi=true,
3832
current='all',

dashboard/build/prometheus/tdg_dashboard_static.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ if WITH_INSTANCE_VARIABLE then
1616
grafana.template.new(
1717
name='alias',
1818
datasource=DATASOURCE,
19-
query=std.format('label_values(tnt_info_uptime{job="%s"},alias)', JOB),
19+
query=std.format('label_values(%s{job="%s"},alias)', [variable.metrics.tarantool_indicator, JOB]),
2020
includeAll=true,
2121
multi=true,
2222
current='all',

dashboard/variable.libsonnet

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@
1616
measurement: '${INFLUXDB_MEASUREMENT}',
1717
alias: '/^$alias$/',
1818
},
19+
metrics: {
20+
// It is expected that every job/measurement with Tarantool metrics would have this one.
21+
tarantool_indicator: 'tnt_info_uptime',
22+
},
1923
}

doc/monitoring/grafana_dashboard.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ To import a specific dashboard, choose one of the following options:
208208
- upload the dashboard JSON file.
209209

210210
Set dashboard name, folder, uid (if needed), and datasource-related query parameters
211-
(InfluxDB source, measurement and policy or Prometheus source and job).
211+
(InfluxDB source, measurement and policy or Prometheus source).
212212

213213
.. image:: images/grafana_import_setup.png
214214
:align: left
@@ -219,7 +219,7 @@ Set dashboard name, folder, uid (if needed), and datasource-related query parame
219219
Troubleshooting
220220
-------------------------------------------------------------------------------
221221

222-
If there's no data on the graphs, make sure that you have set up datasource and job/measurement correctly.
222+
If there are no data on the graphs, make sure that you have set up datasource and picked job/measurement correctly.
223223

224224
If some Prometheus graphs show no data because of ``parse error: missing unit character in duration``,
225225
ensure that you use Grafana 7.2 or newer.

tests/Prometheus/dashboard_compiled.json

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
"pluginId": "prometheus",
88
"pluginName": "Prometheus",
99
"type": "datasource"
10-
},
11-
{
12-
"description": "Prometheus Tarantool metrics job",
13-
"label": "Job",
14-
"name": "PROMETHEUS_JOB",
15-
"type": "constant",
16-
"value": "tarantool"
1710
}
1811
],
1912
"__requires": [
@@ -15174,24 +15167,23 @@
1517415167
"list": [
1517515168
{
1517615169
"allValue": null,
15177-
"current": {
15178-
"text": "${PROMETHEUS_JOB}",
15179-
"value": "${PROMETHEUS_JOB}"
15180-
},
15181-
"hide": 2,
15170+
"current": { },
15171+
"datasource": "${DS_PROMETHEUS}",
15172+
"hide": 0,
1518215173
"includeAll": false,
1518315174
"label": "Prometheus job",
1518415175
"multi": false,
1518515176
"name": "job",
15186-
"options": [
15187-
{
15188-
"text": "${PROMETHEUS_JOB}",
15189-
"value": "${PROMETHEUS_JOB}"
15190-
}
15191-
],
15192-
"query": "${PROMETHEUS_JOB}",
15193-
"refresh": 0,
15194-
"type": "custom"
15177+
"options": [ ],
15178+
"query": "label_values(tnt_info_uptime,job)",
15179+
"refresh": 1,
15180+
"regex": "",
15181+
"sort": 0,
15182+
"tagValuesQuery": "",
15183+
"tags": [ ],
15184+
"tagsQuery": "",
15185+
"type": "query",
15186+
"useTags": false
1519515187
},
1519615188
{
1519715189
"allValue": null,

tests/Prometheus/dashboard_tdg_compiled.json

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@
77
"pluginId": "prometheus",
88
"pluginName": "Prometheus",
99
"type": "datasource"
10-
},
11-
{
12-
"description": "Prometheus Tarantool metrics job",
13-
"label": "Job",
14-
"name": "PROMETHEUS_JOB",
15-
"type": "constant",
16-
"value": "tarantool"
1710
}
1811
],
1912
"__requires": [
@@ -20485,24 +20478,23 @@
2048520478
"list": [
2048620479
{
2048720480
"allValue": null,
20488-
"current": {
20489-
"text": "${PROMETHEUS_JOB}",
20490-
"value": "${PROMETHEUS_JOB}"
20491-
},
20492-
"hide": 2,
20481+
"current": { },
20482+
"datasource": "${DS_PROMETHEUS}",
20483+
"hide": 0,
2049320484
"includeAll": false,
2049420485
"label": "Prometheus job",
2049520486
"multi": false,
2049620487
"name": "job",
20497-
"options": [
20498-
{
20499-
"text": "${PROMETHEUS_JOB}",
20500-
"value": "${PROMETHEUS_JOB}"
20501-
}
20502-
],
20503-
"query": "${PROMETHEUS_JOB}",
20504-
"refresh": 0,
20505-
"type": "custom"
20488+
"options": [ ],
20489+
"query": "label_values(tnt_info_uptime,job)",
20490+
"refresh": 1,
20491+
"regex": "",
20492+
"sort": 0,
20493+
"tagValuesQuery": "",
20494+
"tags": [ ],
20495+
"tagsQuery": "",
20496+
"type": "query",
20497+
"useTags": false
2050620498
},
2050720499
{
2050820500
"allValue": null,

0 commit comments

Comments
 (0)