0

In Grafana v9.3.4

I have the following 2 template variables named instance and mssql_instance.

The first one returns the instance (e.g. "winserver") and the second one return the SQL instances of the instance "winserver" (e.g. "mssqlserver", "dev"). Both of them are coming from Prometheus.

I have another template variable named sql_datasource which returns all the SQL data sources of Grafana (e.g. "winserver_mssqlserver", "winserver_dev", "winserver2_mssqlserver", "winserver2_server2").

In my dashboard I have mixed panels, few of them project metrics from Prometheus and the rest of them project TSQL Queries.

I have implement the Prometheus variables in the Prometheus panels like this:

mssql_user_connections_per_database{instance=~"${instance}:.+",mssql_instance=~"$mssql_instance"}

So when I change the template variables (instance & mssql_instance) all the panel variables are changing accordingly.

I have also implement the SQL data source variable in the SQL panels but this time I have put the variable in the data source field like the following: ${sql_datasource}.

As an addition I have implement a 4th template variable named sql_datasource_auto that combines the 2 variables instance and mssql_instance in order its output to be the same as the sql_datasource. And it looks like the following:

SELECT CONCAT('${instance}', '_', '${mssql_instance}') AS sql_datasource_auto

If I choose instance = winserver and mssql_instance = dev, then the sql_datasource_auto variable will be winserver_dev.

And here comes my question.

Is there any way that, the sql_datasource can always have the same value with sql_datasource_auto?

I tried to find a way in order to combine the values but I didn't succeed.

I don't know if what I am asking is possible because the variables are coming from 2 different data sources.

markalex
  • 8,623
  • 2
  • 7
  • 32
Blax
  • 35
  • 6
  • First of all, why don't use just use `$sql_datasource_auto` instead of `$sql_datasource`? Or even `${instance}_${mssql_instance}` instead both of them? – markalex Apr 05 '23 at 12:53
  • In the panel editor the available Data Source options I have are the following: ${sql_datasource}, Prometheus, `winserver_mssqlserver`, `winserver_dev`, `winserver2_mssqlserver`, `winserver2_server2` – Blax Apr 05 '23 at 13:49
  • You don't need to link two variables, you just need to remove `$sql_datasource` and then rename `$sql_datasource_auto` to `$sql_datasource`. – markalex Apr 06 '23 at 08:12
  • 1
    Even if I remove the `$sql_datasource` variable from the dashboard and rename the `$sql_datasource_auto` variable to `$sql_datasource`. I will not be able to see the `$sql_datasource` (previously named `$sql_datasource_auto`) variable in the panel editor because the panel editor shows only the data sources from the Grafana and the template variables that have as a variable type the value Data Source and the `$sql_datasource` ( prev `$sql_datasource_auto`) is a query not a Data Source type. That's the reason why I need to link the `$sql_datasource` and the `$sql_datasource_auto` variables. – Blax Apr 10 '23 at 09:47
  • Aha, I understand what you want now. Afaik, there is now way to create such a linkage: data source variables are very limited in general. But you could try to do it in reverse: allow user to select data source and later based on it's value calculate `${instance}` and `${mssql_instance}`. – markalex Apr 10 '23 at 10:03
  • Thank you for your response. I will give it a try and I will provide some feedback! – Blax Apr 10 '23 at 10:20

0 Answers0