We have a use case where we create different panels within a single dashboard querying different datasources, say one is prometheus and other ElasticDB.
The dashboard variable will be environment specific, “dev/uat/prod”, upon selection of the variable, the panels will connect to the datasources for specific environment and render the graphs.
Is it possible to get this done ? currently I can see dashboard variable for a single datasource but not sure how I can achieve this if we have different datasources , different environments but single dashboard.
Just to make sure I understand ->
- The user chooses “uat” in a “environment” template variable
- On the dashboard, one graph has an elasticsearch datasource and one graph has a prometheus datasource, they should now both switch to a uat version of Elasticsearch and Prometheus
This is a bit tricky. If was a different type of template variable then maybe you could chain the variables but that won’t work for datasource variables.
The option I can think of is to have multiple dashboards (with dashboard links to be able to switch easily between them), multiple orgs or even multiple Grafanas per environment. This will introduce a new problem - how do you keep the dashboards in sync (if you now have 3 dashboards, how do you make changes).
Provisioning might help there - make the dashboards readonly and put the dashboards in source control.
That is the last option but is not scalable as we have multiple dashboards and each of them dependnet on the environment, so we would end up having to maintain 3 times the dashboards.
If there was any way to enable grouping datasources while defining them, then probably it would be much easier.
Say for instance in our case, we can create a group called Dev and define Prometheus and elastic datasources, same for prod, based on the group selection the datasources get populated.
Can we submit a feature request?
You can always submit a feature request
If you use provisioning, then you would not have 3 times the dashboards. It is another form of templating basically. This is how we handle our different environments for our Kubernetes clusters for example.
We use a language called Jsonnet to programmatically generate the json for dashboards. This is quite advanced so wouldn’t recommend it unless you are talking about a lot of dashboards and environments.
- Provisioning: Provision Grafana | Grafana documentation
- Here is the Grafana jsonnet lib: GitHub - grafana/grafonnet-lib: Jsonnet library for generating Grafana dashboard files.
- Mixins is a related technique: Everything You Need to Know About Monitoring Mixins | Grafana Labs
- Scripted dashboards is yet another technique: https://grafana.com/docs/reference/scripting/