Referencing value from one query to another

Hi Folks,

I am using Grafana for visualizing some data stored in InfluxDB. I want to reference one query to another query. Here is what I mean.

Query A shows the Error Code and Query B shows the Error text. You will notice that in Query B the value “12832” has been written manually. I want it to reference it from the result of Query A. How can I do it?

Cheers,
SD

I think you can do this using the “Dashboard” datasource.

Hi @svetb ,

How exactly? I tried but couldn’t really figure out how to do this. Some screenshots would be helpful!

In the drop down where you’ve currently selected “Mixed” can you select “Dashboard”? If the option doesn’t exist then you probably need to upgrade. Sorry I can’t take a screenshot since I’m on my phone. (Docs)

Hi @svetb,

I share a screenshot. Maybe you can guide me with the next steps.

I do not get any options to use this value to refer to the table with the error strings. This does not allow me to write any queries to query into the required table to get the corresponding string.

Cheers,
SD

Hi @sahebdatta1996 I think I misunderstood your original question. I thought it was about feeding the result of a query in one panel into another panel. I took a closer look at your first screenshot and think I understand your issue better now. Sorry to lead you astray initially.

There may be a direct way to do this also, but I can’t think of it right now. What should definitely work is to set up your first query (A) as a template variable. That would allow you to use its output as the template variable, and set up query B as you need it in the panel. Let me know if I’m making sense?

1 Like

Hi @svetb,

I tried it that way. The problem is template variables reload on refreshing the dashboard. That is not desirable I won’t be getting continuous data on the graph.

Regards,
SD

@svetb, If you can address this, it will also solve the problem.

Yeah good point. Can you see if you get the desired behavior if you set the template variable to refresh “on time range change”? I know it’s not super intuitive, but I just did a quick test (on v7.5.4) and it looks like with that setting the template variable will also get refreshed along with auto-refresh of the panel queries.

1 Like

Regarding your Kapacitor idea…it may be possible to bend Kapacitor to your will like that, but it won’t be pretty, and I wouldn’t recommend it. As @pooh said in the other forum, if you really need to do a join in your query then just use Flux.

3 Likes

Hi @svetb,

I was really stupid not checking the 2nd option. Yet, it worked and solved the specific purpose. Thanks a lot for your support.

Cheers,
SD

1 Like

Good question and perfect answers to solve this problem. I appreciate that, thanks! :handshake:

1 Like

Sorry guys for bothering you but I am trying to do the same thing, except that with a counter value rather than a sum. I basically want to compute the moving average of requests time in, say, 1m window. Now, moving_average() function does not allow a time duration as window width but just an integer representing the number of samples. So I thought: I create a template variable query “countPerMin” that counts the number of requests per minute:

SELECT count(“reqTime”) FROM “autogen”.“userReqTime” WHERE $timeFilter GROUP BY time($interval), “host”

and use the value in my moving average query

SELECT moving_average(“reqTime”, $countPerMin) FROM “autogen”.“userReqTime” WHERE $timeFilter GROUP BY “host”

The problem is that it does not work like this (InfluxDB Error: error parsing query: found ), expected identifier, string, number, bool at line 1, char 34) and I do not know why. I am new in Grafana and might be a stupid error, apologies for that. I would deeply deeply appreciate your help.

Update: as I was saying, I have d


efined the variable completely wrong. Here is the correct one (screenshot).

I’m not clear based on your last post - do you still have the issue? In your first post the issue is clear since the query for $countPerMin returns nothing, so the query that includes a reference to $countPerMin would of course be invalid. But in the last post it looks like you have some valid values for $countPerMin.

Thanks a lot for your answer @svetb. I do not have the error anymore but still I am not able to create a time moving average with a 1m window. I have tried now with a continuous query, but I guess I have messed up everything because I am not able to delete it anymore. My god, what a mess.

This topic was automatically closed after 365 days. New replies are no longer allowed.