简体   繁体   English

Prometheus cAdvisor码头工人监控

[英]Prometheus cAdvisor docker monitoring

I've setup a docker monitoring stack using Prometheus, Grafana and cAdvisor. 我使用Prometheus,Grafana和cAdvisor建立了一个docker监控堆栈。 While using this query to get running containers: 使用此查询来获取正在运行的容器:

count_scalar(container_last_seen{name=~container1|container2})

It picks up the containers allright, as soon as i launch a new container it is picked up right away. 它可以直接拿起容器,一旦我启动一个新的容器就可以立即拿起它。 The problem is when a container is stopped or removed it does not pick it up, it still shows it as a running container. 问题是当一个容器被停止或移除时它不会捡起它,它仍然将它显示为一个正在运行的容器。

From the cAdvisor/metrics endpoint it is removed as soon as the container stops. 从cAdvisor / metrics端点,一旦容器停止,它就会被删除。

Is there something wrong with the query? 查询有问题吗?

(this is what i used for the stack: https://github.com/vegasbrianc/prometheus ) (这是我用于堆栈的内容: https//github.com/vegasbrianc/prometheus

It seems to be related to the amount of time cAdvisor stores the data in memory . 它似乎与cAdvisor将数据存储在内存中的时间量有关

While cAdvisor keeps the data in memory, you still have a valid date in container_last_seen metric. 虽然cAdvisor将数据保存在内存中,但您仍然在container_last_seen指标中有一个有效的日期。 So the count_scalar instruction still 'sees' the container as it has a valid value. 因此count_scalar指令仍然“看到”容器,因为它具有有效值。

In my test setup, cAdvisor keeps the data during 5 minutes. 在我的测试设置中,cAdvisor在5分钟内保存数据。 After this duration, I get the right information out of your formula because the container_last_seen metric has disappeared. 在此期间之后,我从您的公式中获取了正确的信息,因为container_last_seen指标已消失。

You can change this cAdvisor configuration with the --storage_duration flag. 您可以使用--storage_duration标志更改此cAdvisor配置。

--storage_duration=2m0s: How long to store data.

As an alternative if you wan't quick alerting, you could also consider running a query that would compare last seen date with current date: 作为替代方案,如果您不想快速提醒,您还可以考虑运行一个查询,将上次看到的日期与当前日期进行比较:

count_scalar(time()-container_last_seen{name=~"container1|container2"}<=60)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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