2017-06-06 115 views
4

我已经使用Prometheus,Grafana和cAdvisor设置了码头监控堆栈。使用此查询来获得运行容器时:Prometheus cAdvisor码头监控

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

它拿起容器好吗,只要我启动一个新的容器,它立即被拾起。问题是当一个容器被停止或移除时,它并没有拿起它,它仍然显示它是一个正在运行的容器。

从cAdvisor /指标端点作为容器停止它被立即删除。

有什么错查询?

(这是我使用的堆栈:https://github.com/vegasbrianc/prometheus

回答

3

这似乎是有关amount of time cAdvisor stores the data in memory

虽然cAdvisor保存在内存中的数据,你仍然有一个有效日期container_last_seen指标。所以count_scalar指令仍然'看到'容器,因为它有一个有效值。

在我的测试设置,cAdvisor在5分钟内保持数据。在这段时间后,我会从您的公式中获得正确的信息,因为container_last_seen指标已经消失。

你可以用--storage_duration标志更改此cAdvisor配置。

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

作为替代如果你wan't快报警,你也可以考虑运行一个查询,将最后一次看到日期与当前日期比较:

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