Get last value even if outside of time

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

  • What are you trying to achieve?
    get the last value, so there is always a value displayed, even if not:

  • What happened?
    Due to API Limitations I can only fetch data very rarely. Some components does only work with “Event Polling”. So there could be the same data for a long time.

  • What did you expect to happen?
    As said, it is possible that the last entry in db is like 3 days ago, but the value never changed (i just don´t save the same value again, due to very high db usage)
    So currently, if I have the same value a long time, there is no data displayed anymore. Currently I fill in the gaps with previous or linear. But as soon as the last point is out of time I get no data display.
    My goal:
    Always have last data fillable with previous or linear even if out of time scale

  • Can you copy/paste the configuration(s) that you are having problems with?
    My query:
    SELECT mean("value") FROM "..." WHERE $timeFilter GROUP BY time($__interval) fill(previous)

Welcome

What is your data source?

What do you mean?
I use InfluxDB with Node-RED.

If it’s not what you wanted, please let me know
I am relatively new to grafana/influx

Thank you

1 Like

Hi @vito0912,
Maybe you can just set longer time range for that specific panel like on next link?:

https://community.grafana.com/t/each-panel-has-its-own-timeline/79929/4?u=ldrascic

All other panels on that dashboard would have time range from time picker (in upper right corner).

 

Best regards,
ldrascic

so it looks like you are using influxql query language on influxdb. I wonder if there is a way to check the value of mean and conditionally choose the following use of last?

select last(field_1),* from measurement group by *

Thanks for your idea. However, this would only delay the problem and break the statisics, since a 6h view should be the case with me

It seems to work kind of. I modified it a little bit to work with my needs. It now finds the data (the % at top right is shown correctly). And also shows “data outside time range”. But it doesn´t show a graph. Even when using fill(previous)

F is my normal
H is “yours”

what does the data tab show, behind the graph

Thank you for this.

It seems to work OK when the time range is set to get the all last values

Example: Last 12 hours

When I set the time range to Last 5 minutes or Last 1 hour Grafana will exclude all (or some) queries

Any solution to this?

Br,
kd

Best way I found so far: (in fluxDB)

Do a sort of pre-fetch by selecting a slightly larger period, using the fill(useprevious)
And then reducing te selection again to the original range.

import “date”

from(bucket: “Insights”)
|> range(start: date.sub(d: 24h, from: v.timeRangeStart), stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_field”] == “measure_humidity”)
|> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: true)
|> fill(usePrevious: true)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> yield(name: “last”)

1 Like