Using template variable to select a datasource

I’m trying to use templates to select a datasource, based on a different template variable.

I have several Sensu servers deployed to different environments. Grafana can talk to each of these and has them configured as datasources (example: Sensu-Dev, Sensu-QA, Sensu-Prod). I have a template for accessing Graphite data from the different environments (Dev, QA, Prod).

I want my dashboard to be able to present data from both, but I want them to stay in sync without needing to set each template value individually. Basically, I want to have a $environment variable, and have that update a hidden template value for the Sensu datasource. If $environment is set to Prod, then the Sensu datasource becomes Sensu-Prod.

I have tried to set this up using a datasource template, with Sensu as my datasource type, and using the $environment variable in the filter in various ways, but it is not working out.

Any suggestions would be appreciated. TIA


Support for using other variables in the datasource variable regex filter was just merged to master a couple of days ago.

This was merged after we branched of 4.2 (which is going to be released as stable next week). So this merge will only be available in 4.3

1 Like

Hello torkel, thanks for your response so far. I wanted to get clarity of this feature to understand if it is something that I am looking for.

Similar to kilteer, I have a Sensu use case. I have two template variables, $server, $application. I would like the value selected in the first list of $server to refresh / update a list of applications in the second list - $application

Yes, if the query you use for the application variable uses the sever variable it will be update every time you change the server variable

Appreciated … I’ll try that now.

Can not figure out how to do that. Have a variable (called env) of Type: Custom and want that selected value of this is used to prefix another variable of type: Datasource / Cloudwatch. Tried to write a regular expression in the instance name filter but doesn’t seem to work. Only getting “No datasource found”. Please can anyone point me in the right direction? Thanks

Are there data sources defined with the env in name?

  • For example -

Type: custom
values: dev,sit,prod

type: Datasource/Cloudwatch
name: $env-DS

Type: Cloudwatch

  • dev-DS
  • prod-DS

The value of $env would be the first part of the data source name

1 Like