Create Variable and group values

  • What Grafana version and what operating system are you using? 10.X

  • What are you trying to achieve?
    Data Source: Loki
    I have the data in the below hierarchy. I created variables for filtering ApplicationName, Environment, and Hostname

I achieved the below functionality.
i.e., when I choose App1, my Environment filter will show only PROD and UAT and if I choose PROD in Environment filter, my Host filter will show only HOST1, HOST2 and HOST3, HOST7

ApplicationName Environment Hostname
App1 PROD HOST1
App1 PROD HOST2
App1 PROD HOST3
App1 UAT HOST4
App2 UAT HOST5
App2 TEST HOST6
App1 PROD HOST7

Now I have a requirement to add a variable called Group i.e., set of host should be grouped under certain group.
Example:
Group1 should have HOST1 and HOST2
Group2 should have HOST3 and HOST7
Group3 should have HOST4 and HOST5
Group4 should have HOST6

The filter should follow like this APP → Environment → Group → HOST
i.e., if I select Environment as PROD only Group1 and Group2 should be shown in the group filter. And If I choose Group1 from Group filter then the HOST filter should show only HOST1 and HOST2.

I used custom variable to create GROUP variable but I couldn’t proceed further.

  • I am not sure how to link this GROUP variable to filter the HOST variable values
  • I am not sure how to link ENVIRONMENT variable to filter the GROUP variable values

what kind of variables are these?

custom or query?

App, environment and host are query variable
Group is custom variable

what datasource is being queried? mysql, sql server, rest api ?

Data source: Loki

1 Like

chain-vars

1 Like

Do we need to install Business Variable and Table Plugins?
Is it available in 10.0.01 version of grafana?
Can’t we have the Host name in filter as well… so users can filter based on host aswell.
Anyother way without plug-in?
Please advice

Also I dont see Custom Variable “Group”… actually that was my question :slight_smile:
I used custom variable to create GROUP variable but I couldn’t proceed further.

  • I am not sure how to link this GROUP variable to filter the HOST variable values
  • I am not sure how to link ENVIRONMENT variable to filter the GROUP variable values

The filter should follow like this APP → Environment → Group → HOST

1 Like

you will need some query based variable for that

so that you can filter the group using ${environ} as filter

for that you could mock it using infinity plugin with mock environment to group relationship

csv or json data with 2 entries

environ - group

then use filter option of infinity plugin.
unless you can mock this in Loki query.
but this is static

Hi @yosiasz

Hope you’re not clear on my requirement.

In Loki Log, I have data in the following hierarchy
APP → Environment → HOST
I have created Query based Variable for all three and those are working fine.

Now I have a new requirement i.e., I need to group the set of HOSTs under one name, so the filter should follow as below
APP → Environment → Group → HOST

Note: Group is not part of Loki Logs
I have created custom variable Group and added static values for grouping.

Now I don’t know how to link Environment → Group and Group → HOST
i.e., how to apply chain filter from Environment to Group and from Group to Host.

First is it possible?
If yes, can you please share some Grafana dashboard with the above logic implementation or let me know the steps in detail.

Thanks in advance

use this :point_up:t2::point_up:t2: to create the relationship, hand carve it as csv

or a database with those relationships. I would opt for the latter. here is something you could do, apps → environs → groups → hosts (not implemented)

chrome-capture-2024-6-27