如何创建查询以监控 docker 容器一天运行了多少分钟 [英] how to create query to monitoring how many minutes docker containers ran for a day
问题描述
我正在尝试监控 docker 容器,但是在进行查询以监控容器一天运行的分钟数时遇到问题
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
推荐答案
如果您知道 container_last_seen
指标的数据点之间的间隔(它被称为 scrape_interval
,通常是在 Prometheus 配置文件中配置),那么以下查询可用于计算容器在最后一天运行的持续时间(以秒为单位):
If you know interval between data points for container_last_seen
metric (it is known as scrape_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:
count_over_time(
(changes(container_last_seen{id=~"/docker/.*",instance=~"$node"}[<3*scrape_interval>])>0)
[1d:<3*scrape_interval>]
)*<3*scrape_interval>
例如,如果 scrape_interval
等于 10s
,则查询将如下所示:
For example, if scrape_interval
equals to 10s
, then the query will look like:
count_over_time(
(changes(container_last_seen{id=~"/docker/.*",instance=~"$node"}[30s])>0)
[1d:30s]
)*30
此查询使用 PromQL 子查询来计算数量<当 container_last_seen
时间序列至少有一个变化时,code>30s 间隔.
This query uses PromQL subqueries for calculating the number 30s
intervals when container_last_seen
time series had at least a single change.
这篇关于如何创建查询以监控 docker 容器一天运行了多少分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!