-
What Grafana version and what operating system are you using?
Grafana v8.1.3 on linux
-
What are you trying to achieve?
I have created some variables that will call a group of hosts by their environment. It is all working fine in the dashboard but rather than seeing a list of hosts on the drop down menu I would like to give those a display name of the environment they correspond to.
So rather than the lists of hosts seen in the screen shot it would be Env1, Env2 etc but still use that host list in its variable on the report
what you want is key,value pair
env1 : host1, env2 : host2
thanks , how can i specify multiple hosts on each env ? Like this env2 : host1 host2 ?
I am passing them to an IN clause too so I’ll need (‘host1’,‘host2’) to be passed into the report
Yeah that works for multiple hosts so just need to know how to wrap it properly for the query
where host in ( '${var_name:value}')
maybe try this?
Getting there this is what i see in the generated sql
WHERE hostname IN (‘host1 host’)
well change it in your variables to be what you need it to be then
Yeah I’ve just been playing around and done part of it directly in the variable
I’ve done this
env2 : ‘host1’ ‘host2’
Use this in the SQL (${env:raw})
which gives me
(‘host1’ ‘host2’)
But how can I add a , ? As that is the delimiter in the variable builder
env2 : 'host1','host2'
actually I would not do this manually, I would figure out the grouping in the database itself. that way you do not have to come back to this every time you remove a host of a new host shows up in new environment.
this manual approach is not sustainable
create table environments(
environmentid int identity(1,1),
environment_name nvarchar(50)
)
insert into environments(environment_name)
select 'env1' union
select 'env2'
create table hosts(
hostid int identity(1,1),
host_name nvarchar(50)
)
insert into hosts(host_name )
select 'host1' union
select 'host2'
create table environments_hosts(
fk_environmentid int,
fk_hostid int
)
you know the rest.
use these 3 tables for the basis of your variable.
thanks for this . my sql isn’t the best !
I do have them grouped already by env in a table that is how I got the initial list shown on my first screen shot.
It was how to present that to the users as the env name rather than the list of hosts
1 Like