Timestamp of last change of metric

26 views
Skip to first unread message

vienna

unread,
Jun 5, 2020, 5:17:24 AM6/5/20
to Prometheus Users
Hi fellows,

I want to get the timestamp or the time passed since a certain metric has been a certain value, like 1 in this case:

I have an enum value (can make it a Gauge too, if needed) and want to see, when it has been at a certain state the last time, hence getting the timestamp of it. The state in question:
my_metric{label="custom_thing: a"} 1

Currently the metric is this state since couple days:
my_metric{label="custom_thing: b"} 0

Output expected after query:
my_metric{label="custom_thing: a"} 1590743254.8581
or
my_metric{label="custom_thing: a"} 1...@1590743254.8581


When I run

my_metric{label="custom_thing: a"}[1w]

I end up in seeing the timestamps in question, if the change has been within the last week. That approach would be sufficient, I could do different ranges to workaround it. Still the output is like
1 @1590743254.858
1 @1590743554.858
1 @1590743854.858

but I can't just get the most recent timestamp of these.

Any ideas would be appreciated.

BR;v

Brian Candler

unread,
Jun 6, 2020, 7:53:19 AM6/6/20
to Prometheus Users
timestamp(my_metric) gives you the time at which the last sample in my_metric was recorded.

timestamp(my_metric == 1)in principle ought to give you the last time when it was 1, but I think instant queries only look back a few minutes, so you might need to use a subquery.
Reply all
Reply to author
Forward
0 new messages