You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
make CONFIG=config.yml OUTPUT=mydashboard.json build
150
106
```
151
107
108
+
See repository example config [config.yml](config.yml) for detailed info about supported options.
109
+
152
110
You can run tests with
153
111
```bash
154
112
make run-tests
@@ -161,7 +119,7 @@ make update-tests
161
119
It also formats all source files with `jsonnetfmt`.
162
120
163
121
164
-
## Customization
122
+
## Adding your panels
165
123
166
124
If you're interested in building grafonnet dashboards or custom panels,
167
125
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.
198
156
```
199
157
to install dependencies. [`grafonnet`](https://github.com/grafana/grafonnet-lib) library will also be installed as a transitive dependency.
200
158
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
+
```
201
167
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.
204
169
```jsonnet
205
170
# 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';
208
172
```
209
173
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.
211
175
212
176
A row panel can be created by using the following script:
local my_row = common_panels.row('My custom metrics')
218
182
```
219
183
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.
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
262
226
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
rate, # (default false) Whether to transform the metrics as rate
267
232
),
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
-
)
276
233
```
277
234
278
235
To build more compound targets, use `grafonnet` library `prometheus` and `influxdb` templates.
279
236
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 setin 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
-
298
237
To add a target to a panel, call `addTarget(target)`.
299
238
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
0 commit comments