Using output of 1 query in another query

  • What Grafana version and what operating system are you using?
    MAC OS, Grafana v11.2.1

  • What are you trying to achieve?
    I am trying to create an alert, but first Im testing my queries out in the dashboard section. Each Access Point has totalMemory and availableMemory, I am trying to create an alert for access points which have increasing memory.

  • How are you trying to achieve it?
    I am trying to achieve this by using diffrentiation function and seeing how the slope changes with time, if it increases for more than a set period of time then I throw an alert.

  • What happened?
    The diffrentiation function is supposed to take in output from another bunch of queries. But Im unable to figure out how this can be done, I tried the dashboard data source method, but in that you can just view the output of another panel in some other panel.

  • What did you expect to happen?
    I expected that I’ll be able to query output of another query here itself, but is there a workaround this?

  • Can you copy/paste the configuration(s) that you are having problems with?
    A: SELECT mean(“value”)
    FROM “$database”.“$measurement_total”
    WHERE (“$tag1”::tag =~ /^$value1$/ AND “$tag2”::tag =~ /^$value2$/)
    AND $timeFilter
    GROUP BY time($__interval)
    fill(none)
    B: SELECT mean(“value”)
    FROM “$database”.“$measurement_available”
    WHERE (“$tag1”::tag =~ /^$value1$/ AND “$tag2”::tag =~ /^$value2$/)
    AND $timeFilter
    GROUP BY time($__interval)
    fill(none)
    Math expression (($A-$B)/$A)*100

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

  • Did you follow any online instructions? If so, what is the URL?
    I tried following Referencing value from one query to another - #5 by sahebdatta1996
    but quickly realised that I can only apply transformations if I use dashboard as datasource and not more complex queries like I want to.

Welcome @shreyamalik to the Grafana forum.

So no errors, but no output either, right?

I am thinking that perhaps the timestamps of the results from Query A and Query B are not aligned. Maybe try experimenting with the fill function?

Also, are you using InfluxQL?

Yes I am using InfluxQL, so the queries I have written are working perfectly fine, but my doubt is that I want to apply a query on the output of these queries, and then a math transformation on that to create an alert. What are my possible solutions to build a query on top of another query.