Skip to content

Commit c04f2cd

Browse files
doc: describe new approach to manual build
Closes #204 Closes #206 Closes #207
1 parent e2cb2ea commit c04f2cd

File tree

1 file changed

+42
-151
lines changed

1 file changed

+42
-151
lines changed

README.md

Lines changed: 42 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ Refer to dashboard [documentation page](https://www.tarantool.io/en/doc/latest/b
1212

1313
<img src="./doc/monitoring/images/Prometheus_dashboard_1.png" width="250"/> <img src="./doc/monitoring/images/Prometheus_dashboard_2.png" width="250"/> <img src="./doc/monitoring/images/Prometheus_dashboard_3.png" width="250"/>
1414

15-
15+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
16+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1617
## Table of contents
1718

1819
- [Installation](#installation)
1920
- [Monitoring cluster](#monitoring-cluster)
21+
- [Example app](#example-app)
22+
- [Monitoring local app](#monitoring-local-app)
2023
- [Manual build](#manual-build)
21-
- [Customization](#customization)
24+
- [Adding your panels](#adding-your-panels)
2225
- [Contacts](#contacts)
2326

27+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
2428

2529
## Installation
2630

@@ -95,60 +99,14 @@ make test-deps
9599
```
96100
to install build dependencies and dependencies that are required to run tests locally.
97101

98-
To build a static dashboard with no input, run `make` commands.
99-
```bash
100-
make DATASOURCE=Prometheus JOB=tarantool \
101-
WITH_INSTANCE_VARIABLE=FALSE \
102-
OUTPUT_STATIC_DASHBOARD=mydashboard.json \
103-
build-static-prometheus
104-
```
105-
Following targets are available:
106-
- `build-static-prometheus`: Tarantool dashboard for a Prometheus datasource;
107-
- `build-static-tdg-prometheus`: TDG dashboard for a Prometheus datasource;
108-
- `build-static-influxdb`: Tarantool dashboard for an InfluxDB datasource;
109-
- `build-static-tdg-influxdb`: TDG dashboard for an InfluxDB datasource.
110-
111-
Variables for Prometheus targets:
112-
- `DATASOURCE`: name of a Prometheus data source;
113-
- `JOB` (optional, default `tarantool`): name of a Prometheus job collecting your application metrics;
114-
- `WITH_INSTANCE_VARIABLE` (optional, default `FALSE`): build a dashboard with variable which
115-
can be used to select displayed cluster instances;
116-
- `TITLE` (optional, default `"Tarantool dashboard"` for plain dashboard
117-
and `"Tarantool Data Grid dashobard"` for TDG dashboard): dashboard title;
118-
- `OUTPUT_STATIC_DASHBOARD` (optional, default `dashboard.json`): compiled dashboard file.
119-
120-
Variables for InfluxDB targets:
121-
- `DATASOURCE`: name of a InfluxDB data source;
122-
- `POLICY` (optional, default `autogen`): InfluxDB metrics retention policy;
123-
- `MEASUREMENT` (optional, default `tarantool_http`): name of a InfluxDB measurement with your application metrics;
124-
- `WITH_INSTANCE_VARIABLE` (optional, default `FALSE`): build a dashboard with variable which
125-
can be used to select displayed cluster instances;
126-
- `TITLE` (optional, default `"Tarantool dashboard"` for plain dashboard
127-
and `"Tarantool Data Grid dashobard"` for TDG dashboard): dashboard title;
128-
- `OUTPUT_STATIC_DASHBOARD` (optional, default `dashboard.json`): compiled dashboard file.
129-
130-
With `WITH_INSTANCE_VARIABLE=FALSE`, dashboard will contain no dynamic variables and Grafana alerts can be used.
131-
With `WITH_INSTANCE_VARIABLE=TRUE`, dashboard will contain instance dynamic variable (but no inputs).
132-
133-
You can also compile configurable Prometheus dashboard template (the same we publish to
134-
Grafana Official & community built dashboards) with
135-
```bash
136-
jsonnet -J ./vendor/ -e "local dashboard = import 'dashboard/build/prometheus/dashboard.libsonnet'; dashboard.build()"
137-
```
138-
and InfluxDB dashboard template with
139-
```bash
140-
jsonnet -J ./vendor/ -e "local dashboard = import 'dashboard/build/influxdb/dashboard.libsonnet'; dashboard.build()"
141-
```
102+
To build a custom dashboard, run `make build` command with your specific configuration.
142103

143-
To save output into `output.json` file, use
144-
```bash
145-
jsonnet -J ./vendor/ -e "local dashboard = import 'dashboard/build/prometheus/dashboard.libsonnet'; dashboard.build()" -o ./output.json
146-
```
147-
and to save output into clipboard, use
148104
```bash
149-
jsonnet -J ./vendor/ -e "local dashboard = import 'dashboard/build/prometheus/dashboard.libsonnet'; dashboard.build()" | xclip -selection clipboard
105+
make CONFIG=config.yml OUTPUT=mydashboard.json build
150106
```
151107

108+
See repository example config [config.yml](config.yml) for detailed info about supported options.
109+
152110
You can run tests with
153111
```bash
154112
make run-tests
@@ -161,7 +119,7 @@ make update-tests
161119
It also formats all source files with `jsonnetfmt`.
162120

163121

164-
## Customization
122+
## Adding your panels
165123

166124
If you're interested in building grafonnet dashboards or custom panels,
167125
I suggest you to start with reading our grafonnet tutorial:
@@ -198,34 +156,40 @@ You can add your own custom panels to the bottom of the template dashboard.
198156
```
199157
to install dependencies. [`grafonnet`](https://github.com/grafana/grafonnet-lib) library will also be installed as a transitive dependency.
200158

159+
2. Load a configuration, same as in ["Manual build"](#manual-build) section. (You can build it as a dictionary in code instead of parsing a YAML file.)
160+
```jsonnet
161+
# my_dashboard.jsonnet
162+
local config = import 'grafana-dashboard/dashboard/build/config.libsonnet';
163+
local raw_cfg = importstr 'config.yml';
164+
165+
local cfg = config.prepare(std.parseYaml(raw_cfg));
166+
```
201167

202-
2. There are two main templates: `grafana-dashboard/dashboard/prometheus_dashboard.libsonnet` and `grafana-dashboard/dashboard/influxdb_dashboard.libsonnet`.
203-
Import one of them in your jsonnet script to build your own custom dashboard.
168+
3. Import the main template.
204169
```jsonnet
205170
# my_dashboard.jsonnet
206-
local prometheus_dashboard = import 'grafana-dashboard/dashboard/build/prometheus/dashboard.libsonnet';
207-
local influxdb_dashboard = import 'grafana-dashboard/dashboard/build/influxdb/dashboard.libsonnet';
171+
local dashboard = import 'grafana-dashboard/dashboard/build/dashboard.libsonnet';
208172
```
209173

210-
3. To add your custom panels to a dashboard template, you must create panel objects.
174+
4. To add your custom panels to a dashboard template, you must create panel objects.
211175

212176
A row panel can be created by using the following script:
213177
```jsonnet
214178
# my_dashboard.jsonnet
215-
local common_panels = import 'grafana-dashboard/dashboard/panels/common.libsonnet';
179+
local common = import 'grafana-dashboard/dashboard/panels/common.libsonnet';
216180
217181
local my_row = common_panels.row('My custom metrics')
218182
```
219183

220-
Panel with metrics data consists of a visualisation base (graph, table, stat etc.) and one or several datasource queries called "targets". To build a simple visualization graph, you may use `common_panels.default_graph` util.
184+
Panel with metrics data consists of a visualisation base (graph, table, stat etc.) and one or several datasource queries called "targets". To build a simple visualization graph, you may use `common.default_graph` util.
221185

222186
```jsonnet
223187
# vendor/grafana-dashboard/dashboard/panels/common.libsonnet
224188
225189
default_graph( # graph panel shortcut
190+
cfg, # Dashboard configuration
226191
title, # The title of the graph panel
227192
description, # (optional) The description of the panel
228-
datasource, # Targets datasource. If you use default input variables, use grafana-dashboard/dashboard/variable.libsonnet to fill this value
229193
format, # (default 'none') Unit of the Y axes
230194
min, # (optional) Min of the Y axes
231195
max, # (optional) Max of the Y axes
@@ -253,143 +217,70 @@ You can add your own custom panels to the bottom of the template dashboard.
253217
) { gridPos: { w: 6, h: 4 } };
254218
```
255219
256-
To build a target, you may also use `common_panels` utils.
220+
To build a target, you should use `common` utils.
257221
```jsonnet
258222
# vendor/grafana-dashboard/dashboard/panels/common.libsonnet
259223
260-
default_metric_target( # plain "select metric" shortcut
261-
datasource_type, # Target datasource type. Use grafana-dashboard/dashboard/variable.libsonnet to fill this value
224+
target( # plain "select metric" shortcut
225+
cfg, # Dashboard configuration
262226
metric_name, # Target metric name to select
263-
job, # (Prometheus only) Prometheus metrics job. If you use default input variables, use grafana-dashboard/dashboard/variable.libsonnet to fill this value
264-
policy, # (InfluxDB only) InfluxDB metrics policy. If you use default input variables, use grafana-dashboard/dashboard/variable.libsonnet to fill this value
265-
measurement, # (InfluxDB only) InfluxDB metrics measurement. If you use default input variables, use grafana-dashboard/dashboard/variable.libsonnet to fill this value
227+
additional_filters, # (optional) Query additional filter conditions. The structure is{ prometheus: filters, influxdb: filters }, filters have the same format as in cfg
228+
legend, # (optional) Target result legend. The structure is{ prometheus: legend_str, influxdb: legend_str }
229+
group_tags, # (InfluxDB only, optional). Target result group rules. All tags used in legend are expected to be here too
266230
converter, # (InfluxDB only, default 'mean') InfluxDB metrics converter (aggregation, selector, etc.)
231+
rate, # (default false) Whether to transform the metrics as rate
267232
),
268-
269-
default_rps_target( # counter metric transformed to rps shortcut
270-
datasource_type, # Target datasource type. Use grafana-dashboard/dashboard/variable.libsonnet to fill this value
271-
metric_name, # Target metric name to select
272-
job, # (Prometheus only) Prometheus metrics job. If you use default input variables, use grafana-dashboard/dashboard/variable.libsonnet to fill this value
273-
policy, # (InfluxDB only) InfluxDB metrics policy. If you use default input variables, use grafana-dashboard/dashboard/variable.libsonnet to fill this value
274-
measurement, # (InfluxDB only) InfluxDB metrics measurement. If you use default input variables, use grafana-dashboard/dashboard/variable.libsonnet to fill this value
275-
)
276233
```
277234
278235
To build more compound targets, use `grafonnet` library `prometheus` and `influxdb` templates.
279236
280-
To use dashboard-wide input and template variables in your queries you must use `grafana-dashboard/dashboard/variable.libsonnet`.
281-
It imports json object with variable values you neet to set in your queries.
282-
283-
If you want to build a Prometheus dashboard with default input variables, use
284-
```jsonnet
285-
datasource=variable.datasource.prometheus,
286-
job=variable.prometheus.job,
287-
```
288-
in your targets.
289-
290-
If you want to build an InfluxDB dashboard with default input variables, use
291-
```jsonnet
292-
datasource=variable.datasource.influxdb,
293-
policy=variable.influxdb.policy,
294-
measurement=variable.influxdb.measurement
295-
```
296-
in your targets.
297-
298237
To add a target to a panel, call `addTarget(target)`.
299238
300-
To summarise, you can build a simple 'select metric' prometheus panel with
239+
To summarise, you can build a simple 'select metric' panel with
301240
```jsonnet
302-
local common_panels = import 'grafana-dashboard/dashboard/panels/common.libsonnet';
241+
local common = import 'grafana-dashboard/dashboard/panels/common.libsonnet';
303242
local variable = import 'grafana-dashboard/dashboard/variable.libsonnet';
304243
305-
local my_custom_component_memory_graph = common_panels.default_graph(
244+
local my_custom_component_memory_graph = common.default_graph(
245+
cfg,
306246
title='My custom component memory',
307247
description=|||
308248
My custom component used memory.
309249
Shows mean value.
310250
|||,
311-
datasource=variable.datasource.prometheus,
312251
format='bytes',
313252
panel_width=12,
314253
panel_height=6,
315-
).addTarget(common.default_metric_target(
316-
datasource_type=variable.datasource_type.prometheus,
317-
metric_name='my_component_memory',
318-
job=variable.prometheus.job,
319-
))
254+
).addTarget(common.target(cfg, 'my_component_memory'))
320255
```
321256
and a simple rps panel with
322257
```jsonnet
323-
local common_panels = import 'grafana-dashboard/dashboard/panels/common.libsonnet';
258+
local common = import 'grafana-dashboard/dashboard/panels/common.libsonnet';
324259
local variable = import 'grafana-dashboard/dashboard/variable.libsonnet';
325260
326261
local my_custom_component_rps_graph = common.default_graph(
262+
cfg,
327263
title='My custom component load',
328264
description=|||
329265
My custom component processes requests
330266
and collects info on process to summary collector
331267
'my_component_load_metric'.
332268
|||,
333-
datasource=variable.datasource.prometheus,
334-
labelY1='requests per second',
335-
panel_width=18,
336-
panel_height=6,
337-
).addTarget(common.default_rps_target(
338-
datasource_type=variable.datasource_type.prometheus,
339-
metric_name='my_component_load_metric_count',
340-
job=variable.prometheus.job,
341-
))
342-
```
343-
Corresponding InfluxDB panels could be built with
344-
```jsonnet
345-
local common_panels = import 'grafana-dashboard/dashboard/panels/common.libsonnet';
346-
local variable = import 'grafana-dashboard/dashboard/variable.libsonnet';
347-
348-
local my_custom_component_memory_graph = common_panels.default_graph(
349-
title='My custom component memory',
350-
description=|||
351-
My custom component used memory.
352-
Shows mean value.
353-
|||,
354-
datasource=variable.datasource.influxdb,
355-
format='bytes',
356-
panel_width=12,
357-
panel_height=6,
358-
).addTarget(common.default_metric_target(
359-
datasource_type=variable.datasource_type.influxdb,
360-
metric_name='my_component_memory',
361-
policy=variable.influxdb.policy,
362-
measurement=variable.influxdb.measurement,
363-
)),
364-
365-
local my_custom_component_rps_graph = common.default_graph(
366-
title='My custom component load',
367-
description=|||
368-
My custom component processes requests
369-
and collects info on process to summary collector
370-
'my_component_load_metric'.
371-
|||,
372-
datasource=variable.datasource.influxdb,
373269
labelY1='requests per second',
374270
panel_width=18,
375271
panel_height=6,
376-
).addTarget(common.default_rps_target(
377-
datasource_type=variable.datasource_type.influxdb,
378-
metric_name='my_component_load_metric_count',
379-
policy=variable.influxdb.policy,
380-
measurement=variable.influxdb.measurement,
381-
))
272+
).addTarget(common.target(cfg, my_component_load_metric_count', rate=true))
382273
```
383274
For more panel tips and examples, please examine this template dashboard source code and test cases.
384275
385276
To add your custom panels, call `addPanel(panel)` or `addPanels(panel_array)` in dashboard template:
386277
```jsonnet
387278
# my_dashboard.jsonnet
388-
local prometheus_dashboard = import 'grafana-dashboard/dashboard/build/prometheus/dashboard.libsonnet';
279+
local dashboard = import 'grafana-dashboard/dashboard/build/dashboard.libsonnet';
389280
390281
...
391282
392-
local my_dashboard_template = prometheus_dashboard.addPanels([
283+
local my_dashboard_template = dashboard.addPanels([
393284
my_row, my_custom_component_memory_graph, my_custom_component_rps_graph
394285
]);
395286
```

0 commit comments

Comments
 (0)