grafanainfluxdbfluxgrafana-lokigrafana-dashboard

Combining results from two InfluxDB Flux queries in a single Grafana table


I'm using Grafana with InfluxDB and I've encountered a problem when trying to visualize the results of two different Flux queries in a single table.

I have two Flux queries: one fetches the used memory in GB and the other fetches the used memory in percentage. When I try to visualize both queries in a single Grafana table, instead of getting three columns (host, used memory in GB, used memory in percentage), I get results from the second query appended below the results from the first query.

Here are my queries:

Query for used memory in GB:

from(bucket: "telegraf")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "mem")
  |> filter(fn: (r) => r["_field"] == "used")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

Query for used memory in percentage:

from(bucket: "telegraf")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "mem")
  |> filter(fn: (r) => r["_field"] == "used_percent")
  |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> yield(name: "mean")

I am already using the Transformation Reduce, to get the desired 2 columns (host and the metric e.g "Used") [Output]

I tried using the join function in Flux and also attempted merging the results using Grafana's transform features (Merge and Organize fields), but I wasn't able to get the desired table structure.

Expected Outcome: I want a Grafana table with three columns: one for host, one showing the used memory in GB, and another showing the used memory in percentage.

Would I possibly need to approach this differently, maybe by adjusting the query or using another method?

Output before transformations: output2


Solution

  • You can use Grafana join transformation - join those results by host column/tag.