Stats not showing current values when using absolute time range

Grafana version 8.0.3 , Influxdb, Linux
I know there has already been questions about that in the past and I tried to follow them, but cannot make it work!

Hi,
My application records voltages and other measures every second.
The dashboard has a number of variables and panels to analyze those measures over time. All of that works great.

I am now adding a Stat panel to display the “current” measures (the latest one that is no more than a second old). It works when the dashboard uses relative time range, but when the user zooms on a time range or selects an absolute time range, the Stat panel shows the latest measure from that time range.

The Stat panel setup (new user: cannot insert > 2 screen shots):
Calculate / Last (non null) / Numeric Fields

The query:
image

The query options:
image

I have been trying a number of different values for 'Max datapoints", “Min interval” and “Relative time”, but I cannot get the panel to display the latest measure (which is a second old or less) when the user selected time range is not relative.
I also tried with a variable (query), but there is no option to have it update every second (only on dashboard load or change of time range).

Any hint to put me in the right direction would be greatly appreciated. Thank you.
Phil

you mean, you want to ‘separate’ a panel from the date selection?
so what ever date range selected, you always want to show the LATEST (not from that date selection range) but the REAL LATEST metric

I also have the same issue if I understand you correctly
*which I also want to know the answer haha

but to your problem,
my workaround is,
gather all reports that dont use date selection
and create a different dashboard in the same folder
put the reports into this new dashboard
and then disable/hide the date picker

*which I dont think it will work well if it is just 1 stat panel… in 1 new dashboard…

Thanks for your input. Yes, you are right, I want to display the latest metric independently from the date selection (top right of dashboard).
This Stat panel is only a small part of the dashboard so placing it in a different dashboard would be cumbersome for the user.
According to all the posts on the topic, it should work by using a relative time in the query options “Relative time” that overrides the Time picker. But all these posts are related to earlier versions. Maybe functionality has changed?

I was also going to ask for clarification. So for example, if you view the last 3 hours (via the drop down), you see the most current value in the Stat panel. However, if you view, for example, the data from 21-Jun-19:07:19 to 21-Jun-22:18:53, you still want to see that same most current value (let’s say from today), but instead you are seeing the value as of 21-Jun-22:18:53.

My Stat panels behave the same way, which I believe is the intended behavior.

In your query, have you considered putting the Mean() in the Select statement and the Group By statement with a time(1s), like this:
image

1 Like

not sure about previous version as I just jumped in this grafana like 2-3 weeks ago

and yes, as you mentioned, that ‘relative time’ is not working (at least for current version 8) for our issues
that relative time will give you a shift FROM the date selection
it doesnt really separate the panel from date selection

but yes, you understand our issues correctly :slight_smile:

not sure about the Mean() function tho…

  1. mean doesnt mean latest
  2. I never use that query builder in all my reports. I use ‘edit query’ option

but thanks, maybe mean could help @jeanmairep

My understanding is that it did not use to work as I explained above. In this post: Time Range -> Override relative time - #3 by cezarolavo @ [danielgonzalez] says: “Isn’t a bug!! Is feature!!!”

But it seems that in version 7 it became a feature as someone said it in this post: Grafana 7 - Stat panel - Time of last point - #6 by nudelmann [anhhuy2591] writes: " I solved this by using Value “Last” and adding “relative time” (with value “5m” = last 5 minutes) to “Query options” since I want to display current/latest value only (regardless the selected time frame)."

It seems to me that at the moment, when setting a “Relative time” in the query options, it is “Relative” to the last date in the selected date range… and not to now.
Not sure what the current status is for version 8: feature or bug? Would be great if someone from Grafana can set our expectations in that regard and, if it is a feature, give us details on the required setup to make it work.
Thanks
Phil

@jeanmairep what you’re after is actually pretty simple, at least in a sense. Firstly, you are right to observe that fiddling with the time range overrides doesn’t help - since those are always relative to the dashboard range.

But what you can do is just remove the time range filter from your Influx query, and use the last() selector. You may have to use the raw query editor to do that - I’m not totally sure. Something like

SELECT last(voltage) FROM measurement WHERE <your tag filters>

should get you what you need.*

The only issue is with regards to auto-refresh. I don’t think there’s a built-in way to refresh an individual panel, so you’ll indeed need to refresh your whole dashboard in order to get the latest value here.

*to add: you can also hard-code a time filter in your query. E.g. WHERE time > now() - 60s - to ensure that you never show readings that are more than a minute old (in case new readings stop coming in for some reason).

2 Likes

Thanks a lot @svetb :+1:
That was very very easy.

1 Like

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