How do I add thresholds to a tile that indicates Hours since last backup?

Hi, I’ve got a tile that pulls the last backup time from borgmatic logs. The tile color scheme is ‘From thresholds (by value)’ and the unit type is ‘From Now’

What I want is for the tile to be:
green if hours since the last backup is 0-11
yellow if hours since the last backup is 12-23
red if hours since last backup is > 24

I can’t figure out what format the thresholds are looking for. The query returns a timestamp yyyy-MM-dd hh:mm:ss.

Can I somehow convert (transform) that to unixtime and subtract from now()? All my efforts in the transform tab have failed.

TIA

Check this post:

Thanks, I did look into that post before posting my question but unless I’m missing something that is looking at the difference between 2 dates that appear in the logs. I want the difference between the last log date and the current date time - like now() when using grafana with influx.

Got it. It’s not possible as of now, but requested:

1 Like

It may be a bit convoluted, but you can kind of do this. Try:

sum by (instance) (
  last_over_time({SELECTOR}
    |~ "Finished a backup."
    | label_format elapsed=`{{ sub (unixEpoch now) (unixEpoch __timestamp__)
    | unwrap elapsed
  [$__interval])
)
1 Like

Thanks for the response.

Trying what you wrote but getting syntax errors :

sum by(instance) ( 
  last_over_Time( {$label_name=~"$label_value", job=~"$job", instance=~"$instance"} 
    |~ "Finished a backup." 
    | label_format elapsed=``{{ sub (unixEpoch now) (unixEpoch __timestamp__) 
    | unwrap elapsed  
  [$__interval])
)

error: A Status: 500. Message: parse error at line 1, col 20: syntax error: unexpected IDENTIFIER

not sure of the syntax but I also tried with closed braces and a closing tick around the elapsed field label:

sum by(instance) ( 
  last_over_Time( {$label_name=~"$label_value", job=~"$job", instance=~"$instance"} 
    |~ "Finished a backup." 
    | label_format elapsed=`{{ sub (unixEpoch now) (unixEpoch __timestamp__) }}`
    | unwrap elapsed  
  [$__interval])
)

but same error. Any idea what the correct syntax is?

edit: strike that - last_over_Time above shouldn’t have a capital T. Then it worked when I added }} ` to the end of the elapsed function

1 Like