I have a grafana table view pulling from prometheus metrics that has a query something like this
count(up{asg_id="$asg_id"})by{asg_instance}
the table view will show the asg instance id (i-asdfev352) (along with some other stuff) but would also like to show the duration of how long (in minutes) that instance reported in.
so something like this
ID | Duration (m)
-------|-------
i-asdf | 15
i-1234 | 3
i-ev34 | 8
is that possible?
looking at min
or min_over_time
those all work off the value of the metric, not the timestamp
I'm happy to inform you that I was wrong.
You use this query, to find out how long your instance was up:
(time() - min_over_time( timestamp(up) [8d:1m])) / 60
Here:
timestamp(...)
return timestamp what value was scraped,min_over_time( .. [ range : resolution ])
calculates minimum value over provided range with provided resolution. Resolution is required, because we are applying it not to metric, but to aggregation. Result of query can't be bigger than range provided, so choose some guaranteed bigger then uptime value. resolution in this case basically means precision of calculation. But choose those parameters wisely, as they can affect performance of your query,time()
returns current epoch timestamp,/60
converts to minutes.