Consul SD and adding labels via static_config

472 views
Skip to first unread message

Rasmus Rüngenen

unread,
Mar 25, 2021, 6:36:50 AM3/25/21
to Prometheus Users
Hello! I wanted to ask if it would be possible to add labels via static_config to a scrape job that uses the Consul Service Discovery mechanism?

Right now I have tested two solutions and with the static target, the labels are being applied while the Consul SD does not apply.

Consul SD:
  - job_name: 'kubernetes-pods-federation'
    scrape_interval: 30s
    metrics_path: '/federate'
    consul_sd_configs:
      - server: 'localhost:8500'
    relabel_configs:
      - source_labels: [__meta_consul_tags]
        regex: '^.*k8s.*$'
        action: keep
      - source_labels: ['__meta_consul_node']
        target_label: instance
      - source_labels: ['__meta_consul_service']
        target_label: service
      - source_labels: ['__meta_consul_tags']
        target_label: consul_tags
    static_configs:
      - labels:
          env: foo
          region: bar

and second that has static target 
  - job_name: 'consul-agent'
    scrape_interval: 30s
    metrics_path: '/v1/agent/metrics'
    params:
      format: ['prometheus']
    scheme: http
    static_configs:
     - targets: ['localhost:8500']
       labels:
         env: foo
         region: bar

Thanks in advance for the help! 

Aliaksandr Valialkin

unread,
Mar 25, 2021, 1:25:46 PM3/25/21
to Rasmus Rüngenen, Prometheus Users
The `labels` section is unavailable in `consul_sd_configs`. If you want adding labels to all the metrics collected from discovered Consul targets, then add the following relabeling rules under consul_sd_configs section:

- target_label: env
  replacement: foo
- target_label: region
  replacement: bar

See this article for details.

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/2bff96e0-a11f-4d10-b01d-60965241e099n%40googlegroups.com.


--
Best Regards,

Aliaksandr Valialkin, CTO VictoriaMetrics

Rasmus Rüngenen

unread,
Mar 26, 2021, 3:26:24 AM3/26/21
to Prometheus Users

Hey Aliaksandr!

Thank you for the answer, these relabeling rules helped indeed! I will save the medium post to bookmarks as it contains a lot of good examples! 

Best regards,
Rasmus Rüngenen
Observability Platform Developer
Pipedrive
Reply all
Reply to author
Forward
0 new messages