17

For a particular job in Prometheus, it seems like the typical config is something like this:

static_configs:
- targets: ['localhost:9090']

But in the case where I want a dynamic list of hosts, what would be the approach there? I was looking at scrape_config but that doesn't seem to accomplish what I'm after (unless I'm misreading?).

Thank you in advance!

Akshay Shah
  • 323
  • 2
  • 16
Thomas Stringer
  • 5,682
  • 3
  • 24
  • 40

2 Answers2

11

There are several ways of providing dynamic targets to your Prometheus. Please refer the link here

Some of them are:

  • azure_sd_config (for AzureVM metrics)
  • consul_sd_config (for Consul's Catalog API)
  • dns_sd_config (DNS-based service discovery)
  • ec2_sd_config (for AWS EC2 instances)
  • openstack_sd_config (for Openstack Nova instances)
  • file_sd_config (file-based service discovery)

I think what you require is file_sd_config. file_sd_config is a more generic way to configure static targets. You may provide the targets in a yaml or json format. Please follow the link for detailed information.

Akshay Shah
  • 323
  • 2
  • 16
10

If one of the provided service discovery mechanisms doesn't already do what you need, you can use file_sd_configs to provide targets on the fly.

brian-brazil
  • 31,678
  • 6
  • 93
  • 86
  • 1
    There's a nice blog from RobustPerception on this topic [Using JSON file service discovery with Prometheus](https://www.robustperception.io/using-json-file-service-discovery-with-prometheus) (a YAML is also supported) – Franklin Piat Oct 05 '18 at 11:34