![通过 consul 将 Nomad 任务元标签推广到 Prometheus](https://linux22.com/image/714111/%E9%80%9A%E8%BF%87%20consul%20%E5%B0%86%20Nomad%20%E4%BB%BB%E5%8A%A1%E5%85%83%E6%A0%87%E7%AD%BE%E6%8E%A8%E5%B9%BF%E5%88%B0%20Prometheus.png)
我们正在使用 Nomad 来安排任务,然后在 Consul 中注册,然后从 Prometheus 抓取它们。
服务.hcl:
job "myjob" {
group "mygroup" {
count = "1"
task "mytask" {
driver = "docker"
config {
image = "registry/stuff:someVersion"
port_map {
http = 8080
}
}
resources {
memory = 1024
network {
mbits = 100
port "http" {}
}
}
meta {
version = "0.0.1"
}
service {
tags = ["monitoring", "tagone", "tagtwo"]
port = "http"
name = "${JOB}"
check {
type = "http"
port = "http"
path = "/health"
interval = "20s"
timeout = "3s"
}
}
}
}
}
prometheus.yml:
scrape_configs:
- job_name: 'java_apps'
consul_sd_configs:
- server: "1.2.3.4:8500"
scheme: "http"
relabel_configs:
- source_labels: ['__meta_consul_tags']
regex: '(.*),monitoring,(.*)'
action: keep
- source_labels: ['__meta_consul_service']
target_label: service
metrics_path: /prometheus
现在我的问题是:有没有办法将文件meta
中键的值传播service.hcl
到 Prometheus 中?根据 [Prometheus 文档|https://prometheus.io/docs/prometheus/latest/configuration/configuration/#],
重新标记期间,目标上可以使用以下元标签:... __meta_consul_metadata_:目标的每个元数据键值
我的问题有两个:* 什么被视为目标的元数据?* 如何将密钥version
从meta
节传播到 Prometheus 以用作标签?