功能提取不带标签的cAdvisor的Docker映像名称

功能提取不带标签的cAdvisor的Docker映像名称

本文介绍了使用Prometheus的“目标重新标记"功能提取不带标签的cAdvisor的Docker映像名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用普罗米修斯,以及 cAdvisor 来监视我的环境.

现在,我尝试使用Prometheus的目标重新标记",并创建一个标签,该标签的值是Docker容器的映像名称,不带标签.它基于最初刮掉的image标签.

由于某种原因,它不起作用,在调试日志级别运行时未显示任何错误.我可以看到从cAdvisor抓取的指标(例如container_last_seen),但是我新创建的标签不存在.

我的工作配置:

  - job_name: "cadvisor"
    scrape_interval: "5s"
    dns_sd_configs:
      - names: ['cadvisor.marathon.mesos']
    relabel_configs:
      - source_labels: ['image']
        # [REGISTRYHOST/][USERNAME/]NAME[:TAG]
        regex: '([^/]+/)?([^/]+/)?([^:]+)(:.+)?'
        target_label: 'image_tagless'
        replacement: '${1}${2}${3}'

我的标签-image_tagless-在抓取的指标中丢失.

任何帮助将不胜感激.

解决方案

图片标签不是目标标签,它位于指标本身.因此,您应该使用metric_relabel_configs而不是relabel_configs

我在标签寿命上的博客说明了它的工作原理. /p>

I use Prometheus, together with cAdvisor to monitor my environment.

Now, I tried to use Prometheus' "target relabeling", and create a label that its value is the Docker container's image name, without a tag. It is based on the originally scraped image label.

It doesn't work, for some reason, showing no errors when running on debug log level. I can see metrics scraped from cAdvisor (for example container_last_seen) but my newly created label isn't there.

My job configuration:

  - job_name: "cadvisor"
    scrape_interval: "5s"
    dns_sd_configs:
      - names: ['cadvisor.marathon.mesos']
    relabel_configs:
      - source_labels: ['image']
        # [REGISTRYHOST/][USERNAME/]NAME[:TAG]
        regex: '([^/]+/)?([^/]+/)?([^:]+)(:.+)?'
        target_label: 'image_tagless'
        replacement: '${1}${2}${3}'

My label - image_tagless - is missing from the scraped metrics.

Any help would be much appreciated.

解决方案

The image label is not a target label, it's on the metrics themselves. Thus you should use metric_relabel_configs rather than relabel_configs

My blog on Life of a Label explains how this works.

这篇关于使用Prometheus的“目标重新标记"功能提取不带标签的cAdvisor的Docker映像名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 03:02