将目标动态添加到 Prometheus 配置

Dynamically add targets to a Prometheus configuration

对于 Prometheus 中的特定作业,典型的配置似乎是这样的:

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

但是如果我想要一个动态的主机列表,那应该采用什么方法呢?我在看 scrape_config 但这似乎并没有完成我所追求的(除非我误读了?)。

提前致谢!

如果所提供的服务发现机制之一无法满足您的需求,您可以使用 file_sd_configs 即时提供目标。

有几种方法可以为您的 Prometheus 提供动态目标。请参考linkhere

其中一些是:

  • azure_sd_config(对于 AzureVM 指标)
  • consul_sd_config(对于 Consul 目录 API)
  • dns_sd_config(基于 DNS 的服务发现)
  • ec2_sd_config(对于 AWS EC2 实例)
  • openstack_sd_config(对于 Openstack Nova 实例)
  • file_sd_config(基于文件的服务发现)

我想你需要的是file_sd_config。 file_sd_config 是一种更通用的配置静态目标的方法。您可以以 yaml 或 json 格式提供目标。详情请关注link