Prometheus create label from metric label

别说谁变了你拦得住时间么 提交于 2021-01-28 08:32:44

问题


We are running the node-exporter in containers. To quickly identify on which host each node-exporter is running, I created a metric that looks like this: host{host="$HOSTNAME",node="$CONTAINER_ID"} 1

I'm looking for a way to extract the hostname in host= and create a label for each node-exporter instance as a hostname label. I tried numerous configurations and none seem to work. Current prometheus config looks like this:

scrape_configs:
   - job_name: 'node'
     scrape_interval: 10s
     scrape_timeout: 5s
     metrics_path: /metrics
     scheme: http
     dns_sd_configs:
     - names:
     - tasks.master-nodeexporter
       refresh_interval: 30s
       type: A
       port: 9100
     relabel_configs:
     - source_labels: ['host']
       regex: '"(.*)".*'
       target_label: 'hostname'
       replacement: '$1'

回答1:


This is not possible, as target relabelling happens before the scrape.

What you want to do here is use service discovery to have the right hostname in the first place, which is not possible with dns_sd_configs. You might look at something like Consul and https://www.robustperception.io/controlling-the-instance-label/



来源:https://stackoverflow.com/questions/48775064/prometheus-create-label-from-metric-label

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!