[英]Use Prometheus “target relabeling” to extract cAdvisor's Docker image name without tag
I use Prometheus , together with cAdvisor to monitor my environment. 我使用Prometheus和cAdvisor来监控我的环境。
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. 现在,我尝试使用Prometheus的“目标重新标记”,并创建一个标签,其值是Docker容器的图像名称,没有标记。 It is based on the originally scraped
image
label. 它基于最初的
image
标签。
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. 我可以看到从cAdvisor中删除的指标(例如
container_last_seen
)但我新创建的标签不存在。
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. 我的标签 -
image_tagless
- 在已删除的指标中缺失。
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
因此,您应该使用
metric_relabel_configs
而不是relabel_configs
My blog on Life of a Label explains how this works. 我的关于标签生活的博客解释了它是如何工作的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.