Skip to main content
Solved

Coloring last reading time in Grafana [Community Contributed]


Forum|alt.badge.img

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

@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.

View original
Did this topic help you find an answer to your question?

3 replies

ipolomanyi
Practitioner
  • Practitioner
  • 28 replies
  • Answer
  • June 13, 2023

@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.


Dilini Fernando
Seasoned Practitioner
Forum|alt.badge.img+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,
Dilini  


Dilini Fernando
Seasoned Practitioner
Forum|alt.badge.img+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,
Dilini 

 


Reply


Cookie Policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie Settings