"Days since last accident"

390 views
Skip to first unread message

Dave Cadwallader

unread,
May 29, 2018, 8:10:04 AM5/29/18
to Prometheus Users


I'd like to write a PromQL query that tracks the amount of elapsed time since some condition was true.  Specifically, similar to the example above, I've got a metric that should remain at 0 all the time in an ideal case.  When it's not, I'd like to track the amount of time since it was 0.

Is there a way to write a query like this?

Thanks!
Dave

Ben Kochie

unread,
May 29, 2018, 8:20:21 AM5/29/18
to Dave Cadwallader, Prometheus Users
The usual way we track this kind of thing is to have a unix timestamp as a metric.

last_accident_seconds 1527509860

Then you can calculate a number of things:

Time since last accident: time() - last_accident_seconds

Number of accidents in the last 30 days: changes(last_accident_seconds[30d])

This is how we recommend monitoring for things like cron jobs.  job_last_started_seconds, job_last_completed_seconds.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-users+unsubscribe@googlegroups.com.
To post to this group, send email to prometheus-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/1c953bbf-93cb-45ac-9f8f-4e30a6d5ec14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Cadwallader

unread,
May 29, 2018, 10:22:38 AM5/29/18
to Ben Kochie, Prometheus Users
Awesome, thanks Ben!!!
Reply all
Reply to author
Forward
0 new messages