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
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:
opened 01:26PM - 02 May 24 UTC
type/feature
**Is your feature request related to a problem? Please describe.**
I have often… times encountered problems which would be solved by being able to use a function which would return the current time/date/timestamp, similar to prometheus' `time()` function. As an illustrative example, imagine a script which every day logs the timestamp it ran at, and I wanted to write a rule that would check this timestamp to ensure that it does in fact run everyday. In PromQL, this would look something like:
`(time() - my_script{output='timestamp'})/3600 < 24`
However, I have found no functionality in LogQL which could do something similar.
**Describe the solution you'd like**
As mentioned, I'd like LogQL to have a function like `time()` in PromQL.
**Describe alternatives you've considered**
I have tried a few things with `__timestamp__`, but that function seems to be built only for templating and not log/metric querying. Or maybe I am doing something wrong.
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