Coloring last reading time in Grafana [Community Contributed]


Hi! I want to display the latest time when new data come in to a time-series and color it based on the following rule:

-Latest value within 48 hours, shown latest time in green

-Latest value more than 48 hours, shown latest time in red

(With that rule, the numbers should be in green, green and red in my picture)


I struggle to find the correct thresholds to make this 48 hours rule work. It seems to be related to unix time. Have thought about calculate the time difference between current time and latest updated time, but didn’t make it work in time series custom query.


Any suggestion would be appreciated. :)


Best answer by ipolomanyi 13 June 2023, 09:45

View original

3 replies

Userlevel 1

@Yanzhu Yu hi!
I think you should apply a few Grafana transformations to make that work.

Extract field first and divide it by 1000:



Subtract that value from the current time:


Divide by 86400 to get the number of days, or 3600 to get hours:

When you have time difference in hours/days, you should be able to use thresholds.

NB: I only used the latest datapoint, but if you have multile, you’d need to reduce that with the latest one before doing other transformations.

Userlevel 4
Badge +2

Hi @Yanzhu Yu,

I hope you were able to solve the issue. As of now, I will solve this thread. If you have any questions please feel free to post in Cognite Hub.

Best regards,

Userlevel 4
Badge +2

Hi @Yanzhu Yu,

We appreciate your contribution to our community hub! We have chosen to move your article to our hub's How-To section as it will greatly benefit other members of our community. Thank you for your understanding, and we look forward to seeing more great contributions from you in the future! 

Best regards,