通过 consul 将 Nomad 任务元标签推广到 Prometheus

通过 consul 将 Nomad 任务元标签推广到 Prometheus

我们正在使用 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_:目标的每个元数据键值

我的问题有两个:* 什么被视为目标的元数据?* 如何将密钥versionmeta节传播到 Prometheus 以用作标签?

相关内容