如何配置prometheus.yml以仅为node-exporter刮取正在运行的容器 [英] How to configurate prometheus.yml to scrape only running containers for node-exporter

查看:126
本文介绍了如何配置prometheus.yml以仅为node-exporter刮取正在运行的容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 node-exporter 从docker swarm节点收集主机的资源时,grafana/prometheus出现了问题.

I have a problem with the grafana/prometheus when I used node-exporter to collect host's resources from docker swarm nodes.

我仅用一个群集节点进行了测试.当我使用查询
label_values(实例的node_uname_info {job ="node-exporter"}}).结果还返回了已停止容器的旧IP和正在运行容器的IP .我希望它只返回正在运行的容器的IP.您可以看到下面的图像,它始终显示节点导出的容器的ip.

I tested with only one swarm node. When I used the query
label_values(node_uname_info{job="node-exporter"}, instance) in Grafana variables. The result returned the old ip of stopped containers and the ips of running container as well. I want it only returns the ip of running container. You can see the image below, it shows the ip of node-exported containers all the time.

但是实际上,一个1容器正在与ip 10.0.1.12:9100一起运行.其他ip是已启动和已停止的node-exporter容器的旧ip.这是这些容器创建的时间序列.

But actually, one one container is running with the ip 10.0.1.12:9100. The other ips were the old ip of node-exporter containers that started and stopped. Here is the time-series that these contianer were created.

我认为我们可以使用#relabel_config在prometheus.yml中配置scrape方法,但我对此并不熟悉.这是我从 https://github.com/stefanprodan/swarmprom 获得的抓取方法..>

I think we can configurate the scrape method in prometheus.yml with the #relabel_config but I am not familiar with it. Here is the scrape method I got from https://github.com/stefanprodan/swarmprom.

  - job_name: 'node-exporter'
    dns_sd_configs:
    - names:
      - 'tasks.node-exporter'
      type: 'A'
      port: 9100

您知道如何通过在prometheus.yml中添加一些属性来过滤仅运行的容器.非常感谢您的考虑.

Do you know how to filter the only running containers by adding some attribute in prometheus.yml. Thank you so much for your consideration.

推荐答案

基于最后的注释,您可以使用以下模式修改查询:

Based on the last comment, you can modify the queries using the following pattern:

min ignoring (instance) (<query without instance>)

(示例)查询

rate(cpu_time_seconds{instance="$instance", otherLabel="otherValue"}[5m])

成为

min without (instance) (rate(cpu_time_seconds{otherLabel="otherValue"}[5m])

此处的聚合函数相对不相关,因为一次只能有一个值.

The aggregation function is relatively irrelevant here, as you only have one value at a time.

此外,您还可以从仪表板中删除 instance 变量

Additionally you can remove the instance variable from the dashboard

这篇关于如何配置prometheus.yml以仅为node-exporter刮取正在运行的容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆