Thomas Stringer
Thomas Stringer

Reputation: 5862

Dynamically add targets to a Prometheus configuration

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!

Upvotes: 20

Views: 42389

Answers (2)

Akshay Shah
Akshay Shah

Reputation: 353

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.

Upvotes: 14

brian-brazil
brian-brazil

Reputation: 34142

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.

Upvotes: 11

Related Questions