How can i set a threshold based on the comparison with the current time

Hi, I want to set the ‘now’ variable as the threshold.

I’m fetching the last timestamp value from Elasticsearch and I want to compare it with the current time to display it in different colors.
For example, if the timestamp value is 4/25 16:00 and the current time is 4/25 16:25, the difference is within 1 hour so I want to display it in green. If the difference exceeds 1 hour, I want to display it in red.
However, I’m unsure how to incorporate a variable into the threshold value. Is there a way to do this?

Below is the current appearance of the panel I’m using.
image

  • What Grafana version and what operating system are you using?
    Grafana v10.4.2 (701c851be7)

  • What are you trying to achieve?
    Comparing current time with timestamp values to indicate color differences.

  • How are you trying to achieve it?
    set the big int value as the threshold.

Did you ever get a solution for this? I have the same issue.

I, too, am looking for a solution to this. Anyone has an answer?

You can solve your problem using follow the below give steps.
Step : 1 Get last updated time form your respected datasoure
Step : 2 get Latest time using now ()
Step : 3 Calculate the difference between Current time and Last Updated time
Using following query

SELECT 
  NOW() AS current_time,
  MAX(updated_at) AS latest_time,
  NOW() - MAX(updated_at) ::timestamp AS time_difference,
  ROUND(EXTRACT(EPOCH FROM NOW() - MAX(updated_at)::timestamp) / 3600, 2) AS time_diff_hours
FROM 
  sensors_data;

Step : 4 Steup Visulization as a State
Calculation = Last*
Field = calculatd Time Difference (field Name)
Unit = hour
Add Theresold
0 green
1 red
24 other

  • Final Output