基于文件的服务发现方式不需要依赖其他平台与第三方服务,用户只需将要新的target信息以yaml或json文件格式添加到target文件中 ,prometheus会定期从指定文件中读取target信息并更新。

vim /usr/local/prometheus-2.1/targets.json
[
  {
    "targets": [ "192.168.20.136:9100"],
    "labels": {
      "instance": "nodeone",
      "job": "expor_test1"
    }
  },

  {
    "targets": [ "localhost:9090"],
    "labels": {
      "job": "prometheus"
    }
  },

  {
    "targets": [ "192.168.20.137:9100"],
    "labels": {
      "instance": "nodetwo",
      "job": "expor_test2"
    }
  }
]

Prometheus配置文件

global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
  - static_configs:
    - targets: ['localhost:9093']

rule_files:
# - "/usr/local/prometheus-2.1/rule.yml"
# - "/usr/local/prometheus-2.1/rule2.yml"

scrape_configs:

- job_name: 'file_ds'   #此处定义了自动发现的采集任务
  file_sd_configs:
    - files:
      - targets.json         #采集文件名

启动prometheus

./prometheus &

查看web界面targets 出现targets.json 所定义的3个job。

相关文章:

  • 2021-06-28
  • 2021-11-06
  • 2022-03-03
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-15
  • 2022-12-23
  • 2021-12-20
  • 2021-12-16
  • 2021-05-17
  • 2021-07-05
相关资源
相似解决方案