This tool is used to render the Grafana dashboard with predefined variables statically. (supports Grafana v6+)
Grafana dashboard supports template variables, which will improve the expression, user can easily use predefined variables to render the dashboard dynamically, not only the queries including these variables can be rendered, but also the panels can be repeated by variable. This reduces a lot of toils to create multiple similar graphs which only differ in some arguments.
But the Grafana alerts can't be supported when using template variables, you might use alertmanager or other approaches to implement.
-
define a template dashboard in Grafana
A template dashboard is the same as a dashboard with template variables, define the variables you will customize later. -
create the configuration for rendering variables
The format is in yaml file, for example you definedSERVICE_NAME
andTEST_VAR
as variables, you need to set the values they might have, in this case,news
,payment
,user
.
The context accompanied with the value is that when one value is specified, which context in that panel should use, this can be the case when you need to setup theTEST_VAR
tolocal_payment
in that panel whenSERVICE_NAME
ispayment
.--- vars: - name: SERVICE_NAME values: - context: TEST_VAR: local_news value: news - context: TEST_VAR: local_payment value: payment - context: ~ value: user - name: TEST_VAR values: - context: ~ value: global
-
Render it! The following command will call the Grafana API to render the template dashboard and finally create another rendered dashboard.
go run cmd/grafops/grafops.go --host http://localhost:3000 -u RKAQZi9Zk --basic_auth $GRAFANA_USERNAME:$GRAFANA_PASSWORD -c ./config.yaml
go build -o grafops cmd/grafops/grafops.go
mv grafops /usr/local/bin
This introduces how to render the test dashboard on your local machine.
-
Run Grafana Use docker to run Grafana dashboard in your local environment.
docker run -p 3000:3000 grafana/grafana:6.5.0
-
Import Grafana test dashboard Access http://localhost:3000/dashboard/import and paste the
samples/grafana_test_dashboard.json
to the dashboard content.
-
Provision an API Key in Grafana Access http://localhost:3000/org/apikeys to create an editor/admin API key.
-
Render the dashboard
go run cmd/grafops/grafops.go --host http://localhost:3000 -u VoUygmrWz --basic_auth <auth-key> -c config.test.yaml
There will be a rendered dashboard created.