简体   繁体   中英

PromQL: time from last value of a series

I have multiple server instances that are exporting various metrics. Frequently, some instances are offline, therefore, they don't export anything.

I would like to create a panel that would simply display a table in which each server instance is represented by a row and states how long (hh:mm) the server has been offline (ie a duration between last exported datapoint in a series and now).

Example output:

instance  | offline_duration
----------------------------
instance1 | 00:00
instance2 | 01:12
instance3 | 25:10

I have multiple other use-cases in which I would appreciate both the ability of selecting the last value (of all times) and measuring time duration from now to the series data point.

Semantically, I was hoping for something like now() - timestamp(last_over_time(my_metric)) but this has a lot of obvious problems such as last_over_time requires a range-vector.

Is this even possible? Thank you for your help!

This seems to be possible with subquery:

time() - (
  max_over_time(
     ( timestamp(your_metric) )[2h:1m]
  )
)

2h here is the time window - how far into the past query should look for last data point

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM