How to get the latest value from range, based on time

I am using Grafana 4.5.2. with ES data source and have a dashboard that displays single stats and graphs for server status overview.

I want to display current value in all single stats. Meaning, get the most latest value according to time from the query results.
It is not clear to me how to do that as using ES the queries contain time range and there are options to display max/min/count etc. but not last/current value.

I thought to limit the number of received results to just one based on interval template parameter. But what I do not understand is the relation between the refresh interval and step count.

Single stat query (no option to choose current/latest, based on time range):

currently the refresh rate is 1 min and the data in ES is updated every 1 min.

up-time get query:
{“search_type”:“query_then_fetch”,“ignore_unavailable”:true,“index”:“beaconindex”} {“size”:0,“query”:{“bool”:{“filter”:[{“range”:{“private_data.timestamp”:{“gte”:“1516269112707”,“lte”:“1516269172707”,“format”:“epoch_millis”}}},{“query_string”:{“analyze_wildcard”:true,“query”:“private_data.kes_hostname.keyword:lilach\-centos\-vm.com”}}]}},“aggs”:{“2”:{“date_histogram”:{“interval”:“2m”,“field”:“private_data.timestamp”,“min_doc_count”:0,“extended_bounds”:{“min”:“1516269112707”,“max”:“1516269172707”},“format”:“epoch_millis”},“aggs”:{“1”:{“max”:{“field”:“private_data.systemMetrics.systemData.system.uptime”}}}}}}

What is the relations between the step count and the refresh/query interval?
22

1 Like

Hi,

You select current in the Stat drop down:

image

Marcus

2 Likes

Thanks.
Currently I am working with the Average, but as far as I understand it is an average operation on all received values in query result.
Isn’t that the case?

1 Like

What I wan’t, at least in the single stats gauges, is to query and get single result or select from the results the one with the max timestamp

Yes, in the Stat drop down you select Current instead of Average. That will display the last value in the single stat panel.

Marcus

1 Like

thanks, Marcus, you are correct and been very helpful.
Singlestat Panel

Hi Marcus,
I have additional questions regarding above:

  1. I get N/A from time to time in the Guages, when using Current. Why is that?
    I am using time range override relative time last 1m
    22
    56
  2. I can’t find “Current” in Table settings. Is there a way to use Current value in Tables?
  3. What is the relation between the query and the Option for value? it is confusing…I use Max in query yet set Current in Options-> value
    15

Do you get it when not using override relative time? Does it make a difference changing it to 5m? Please refer to How To Use Grafana's Query Inspector to troubleshoot issues and include the complete request/response from query inspector.

Have a look at time series aggregations documentation for table panel.

Not really sure what you mean. The max is per given time unit if that makes sense, You group by date histogram which result in several max values per time unit. I would sugugest you to refer to How To Use Grafana's Query Inspector to troubleshoot issues and inspect the data coming back. That will hopefully give you a greater understanding. Or use the same query in a graph panel.

Marcus

thanks. regarding 2. I am using table of type Table and not Time series aggregation because it doesn’t suit the required table content.

Then you cannot use Current.

Marcus

I am was having similar issue, using the 6.0.x I was able to display the “single stat” value, But when I migrated to 7.0, It gives me count, (since the singlestat panel is depreceated in 7.0)

Any idea how can I fix this ?