Dashboard Variables

Hi,

Env:
rh9
grafana 10.1.4.-1
influxdb2 2.7.1.-1

I am trying to graph interface traffic Data stored in influxdb ( source is checkmk ) . I got it working to display In and Out Traffic and Status. I was able to use host_name and service_name as dashboard Variables to filter the output via pull down menu. ( show tag values …)

But what i actually want to hide the host and service (interface ) name in Grafana , and want to specify which host_name and service_names are able to be viewed, and put a human readable Business Info into the “Description” .

So i came up with an idea to build a csv with 4 fields ( i have it also now in a postgres ) . The Total list will be about 20 Region , total 200 rows)

Region,Description,host_name,service_name . ( Region,Description is unique , so a selected Description has the corresponding host and service name )

I have now created a Variable to pull down the Region and Description, but i have no idea how i am now able to set the corresponding host_name and service_name variable to add to the dashboard queries for the In and Out metrics.

Currently i use following variables . ( postgres )

psql_region: select distinct(region) from interfaces
psql_description: select distinct(description) from interfaces where region = ‘$psql_region’

i would need to set the corresponding host and service variable for the selected “Description” .

I see there is a possibility to regex named captures to show different value to text ? , but i am not sure if this will work.

Currently i am using this query for the Interface source in Influxdb2.

SELECT mean(“value”) FROM “out” WHERE (“host_name”::tag = ‘$host_name_influx’ AND “service_description”::tag = ‘$service_name_influx’) AND $timeFilter GROUP BY time(5m) fill(none)
SELECT mean(“value”) FROM “in” WHERE (“host_name”::tag = ‘$host_name_influx’ AND “service_description”::tag = ‘$service_name_influx’) AND $timeFilter GROUP BY time(5m) fill(none)

The Variables here are the show tag values from influxdb2, those need somehow to be changed to the postgres sourced values without selecting them directly ( only the Description )

Sry for the wrong wording. I started with influx and grafana 2 days ago .

Thx for any help or hints.

Best regards, Dietmar

Welcome @dietmarg

where did the values for these variables originally come from?

Hi,

This was my first try with Variables pulling from influxdb.

host_name_influx : SHOW TAG VALUES WITH KEY = “host_name”
service_name_influx: SHOW TAG VALUES WITH KEY = “service_description” where host_name = ‘$host_name_influx’ and “service_description” =~ /Interface/

Those TAG is sent with the checkmk Metric output.

But actually i need those for the metric output, but not show it as a selection.

thx, Dietmar

1 Like

Hi,

i tried with a new Variable build and regex’ed with value and text .

psql_test:
query:
select ’ header=“’ || description || '”,daten=“’ || host_name || ‘;’ || service_name || '”’ from interfaces
regex:
/header=“(?[^”]+)|daten=“(?[^”]+)/g

So with this i get the description as value shown in the pull down menu.

and with ${psql_test:__text} i see the Daten output . ( actually reversed - but anyway )

But now i have “host_name;service_name” in one Variable. I would need to extract those 2 to be able to use it in the influxdb query like

SELECT mean(“value”) FROM “out” WHERE (“host_name”::tag =~ /^${psql_test:__text}$/ AND “service_description”::tag =~ /^${psql_test:__text}$/) AND $timeFilter GROUP BY time(5m) fill(none)

but this does not work, no output . ( i thought it should find data with regex value:__text , but no …

… all in all trial and error mode :slight_smile: .

Any help would be great, thx, Dietmar

But i still miss a piece to get it done

Time to migrate to influx flux language and buckets and all

You will get much richer functions and control would be my recommendation

But before that please post your sample data as inline csv

Date,tag,hostname
2023-10-11,xyz,server01

So we can have your data in our environment to test things out

1 Like

Hi, thx i have very little time today. but i will come back .

thx for your help, br Dietmar

Hi,

I have created a FLUX Datasource and trying to get this working. I have some problems with splitting the Dashboard Variable Value into 2 variables which is needed for the query , here is my not working sample :slight_smile:

${psql_list:__text} contains “hostnameA;Interface4711” from the Dashboad Variable.

import “strings”

parts = strings.split(v: ${psql_list:__text}, t: ;”)
my_host_name = parts[0]
my_service_name = parts[1]

from(bucket: “checkmk”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “out”)
|> filter(fn: (r) => r[“host_name”] == ${my_host_name})
|> filter(fn: (r) => r[“service_description”] == ${my_service_name})
|> filter(fn: (r) => r[“_field”] == “value”)
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
|> yield(name: “mean”)

I know that the query itself works , and i see with the query inspector that the dashboad Variable is translated in the split function.

I tested the dashboard variable in the query and it got translated in the query inspector …

But i have no idea how to get the new splitted variables used in the query . ( the assignment is just wrong )

No skill on programming - just using search + trial and error . For the query itself i used the query editor from influx web gui and copied it over …

Thx for any help,
Br, Dietmar

Please share the two (?) queries that you created in the variable screen of Grafana and what you see when you click Run Query.

Something like this:

Hi,

I have desribed the Dashboard variables above . The have a different Datasource ( postgres ) , and is need to select a “Business Line Desription of In/Out Bytes”, which Text and Values to “HostnameA;Interface4711” . This works all as i expect, regex them in "pulldown header and set the value als Variable .

This is the postgres query , and the regex .

query name : psql_list
query source : postgres
query : select ’ header=“’ || description || '”,daten=“’ || host_name || ‘;’ || service_name || '”’ from interfaces
regex : /header=“(?[^”]+)|daten=“(?[^”]+)/g

At the End i want a mapping from a “Human readable Text” to Host_name and service_name , as pull down Menu . There will be about 200 Entries for this mapping .

The postgres source with “nice selection description” with text and “hostname;Interface” as value is the selection for the influxdb source given the in and out bytes.

The key Problem i want to have only 1 Selection in dashboard , but need 2 Variables in the query . ( same Interface/Service name is possible on different hostnames, the service_name is not unique ) .

I hope describing it ok ?

Just thought to build the variable select with a { key = value, key = value } output syntax and try to pull off the environment varible in the query with ${psql_list:__text.hostname} - does this work maybe ?

thx, dietmar

Hi,

I have build Dashboard Variables with text / values which shows.

${variable} = “This is the Business Description to Building X” ( pull down )
${variable:_} = {hostname = “HostnameA” , service_name = “Interface Port-channel1”}

But i cannot access the key value like to be used in the influxdb filter query . like ${variable:_.hostname} .

I need the hostname and service_name in the influx query.

my trial an error continues :slight_smile: .

thx ,Dietmar