Defining a Grafana page ${variable} from the middle of a query result

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

v8.5.15

  • What are you trying to achieve?

Trying to define a dashboard variable (${db_role}) from a node “in the middle” of a graphite query response, including the “filtering” at the end of the query…

Given we have variables like:
database.monitoring.production.by_role.*.by_user.*.connections

(1) It was easy to create a dashboard variable for tax-related users:
Dashboard → Settings → Variables: db_user
→ Query: database.monitoring.production.by_role.*.by_user.*tax*
→ Regex: EMPTY

(2) now we cannot figure out how to get a similar list for variable $db_role that is restricted those *tax* users we matched in (1).

  • How are you trying to achieve it?

In my perfect world, Dashboard → Settings → Variables db_role
→ Query: aliasByNode(database.monitoring.production.by_role.*.by_user.*tax*, 4)
→ Regex: EMPTY

But even trying crazy Regexen like /.*[.]production[.]([^.]*)[.]no_cluster.*/ haven’t helped.

  • What happened?

Everything we’ve tried gives:
→ Preview of values: None

  • What did you expect to happen?

→ Preview of values: reservations_db, partners_db, clients_db, …

  • Can you copy/paste the configuration(s) that you are having problems with?

No.

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

No.

  • Did you follow any online instructions? If so, what is the URL?

the closest I could find was about extracting key=value style labels, and I don’t think that’s relevant because this data is in graphite backend, and doesn’t have any k=v style nodes.

You need to use expand() function over your query. Please see this Github issue.
Please note that your graphite installation should have expand API support, but as far as I know both graphite-web 1.1 and both carbonapi flavors support it.

1 Like

Perfect!!

For future searchability…
in the variable declaration, I have

  • Query: expand(database.monitoring.production.by_role.*.by_user.*tax*)
  • Regex: \.by_role\.(.*)\.by_user\.