prometheusprometheus-net

Prometheus: wildcard dns - based discovery


In the prometheus documentation, there is an example about service discovery using dns, in which the following snippet should be added to the configuration file:

scrape_configs:
- job_name: 'myjob'

  dns_sd_configs:
  - names:
    - 'telemetry.eu-west.api.srv.example.org'
    - 'telemetry.us-west.api.srv.example.org'
    - 'telemetry.eu-west.auth.srv.example.org'
    - 'telemetry.us-east.auth.srv.example.org'

My question is whether a wildcard based pattern can be applied, in the likes of:

scrape_configs:
- job_name: 'myjob'

  dns_sd_configs:
  - names:
    - '*.eu-west.api.srv.example.org'

If not, is the usage of an A record that resolves to all the IP addresses that need to be scraped (i.e. monitored by prometheus) the way around this?


Solution

  • This is not possible, as wildcards aren't part of the DNS network protocol. ($GENERATE is a templating feature inside things like Bind, is doesn't appear on the network).

    If not, is the usage of an A record that resolves to all the IP addresses that need to be scraped (i.e. monitored by prometheus) the way around this?

    Yes, that's one way though you'll only get the IP address then. If you need more metadata than that, a different SD would be best.