I am trying to monitor docker containers, but I have problems when making a query to monitor how many minutes the container runs in a day
count(rate(container_last_seen{id=~"/docker/.*",instance=~"$node"}[1d]))
this is my query to show how many container run in a day, but i don't have idea for monitoring how many minutes container runs in a day
If you know interval between data points for
container_last_seen
metric (it is known asscrape_interval
and is usually configured in Prometheus config file), then the following query could be used for calculating the duration in seconds when container was running during the last day:For example, if
scrape_interval
equals to10s
, then the query will look like:This query uses PromQL subqueries for calculating the number
30s
intervals whencontainer_last_seen
time series had at least a single change.