Varibale in variable

Hi Team,

I’m new to grafana. I’m wondering if grafana dashboard has an option with the following description or please help me with the mentioned problem statement.

We have a different number of containers running on various hosts. some hosts have less than 3 containers running whereas few hosts have more than 10 containers.

The problem statement is when I select a host from host variable dropdown as shown in the image, container variable dropdown should show only it’s containers. grafana-forum-variables

I can’t have all containers names in single variable as it will be a lengthy list.

For template variable of container, do you get the list from some API or db?
You can always check e.g.

Query in variable $container will look something like below whereas $hostlist is the variable which has list of hosts and selected value will reflect here in below query -
select container from (select container, host from where host = any(array[$hostlist]::text[])))

The second variable will update itself whenever first variable selected value changes.

Also, you need to decide whether you want to provide multiple choice for selecting options from both dropdown, which you can turn on on the variables setting itself.
Hope this helps!!

Hi Seems,

Thanks for the response. I tried mentioned query it’s showing no variables.
To elaborate my question,
I have 5 hosts with different containers as mentioned below
hostx: cx1, cx2, cx3, cx4
hosty: cy1, cy2, cy3, cy4, cy5, cy6, cy7
hostz: cz1, cz2, cz3, cz4, cz5, cz6, cz7, cz8,cz9, cz10
hostf: cf1, cf2
hosta: ca

My variables are hosts, containers.

Please help me in defining at this phase with defining variables.
How to point containers to specific host.
should I need any extra variables?

Hello @arvin495, please check out chained variables in Grafana documentation, that should solve your problem and answer your questions. :slightly_smiling_face:

1 Like