金庆的专栏

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  423 随笔 :: 0 文章 :: 454 评论 :: 0 Trackbacks
Prometheus动态配置目标

(金庆的专栏 2018.4)

最简单的配置是静态目标:

scrape_configs:
  - job_name: 'prometheus'

    static_configs:
      - targets: ['localhost:9090', 'localhost:9100']
        labels:
          group: 'prometheus'

更改此文件后,可以发送 SIGHUP 触发配置重新加载。

Prometheus 提供了服务发现功能,可以从 consul, dns, kubernetes, file 等等多种来源发现新的目标。
其中最简单的是从文件发现服务。

例如 /root/prometheus/prometheus.yml 配置如下:

global:
  scrape_interval: 15s
  evaluation_interval: 15s
scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['127.0.0.1:9090', '127.0.0.1:9100']
        labels:
          group: 'prometheus'
  - job_name: 'test'
    file_sd_configs:
      - files: ['/etc/prometheus/test_sd_config/*.yml']
        refresh_interval: 5s

用 docker 启动 prometheus:

docker run -d --net=host \
  -v /root/prometheus:/etc/prometheus \
  --name prometheus-server \
  prom/prometheus

创建 /root/prometheus/test_sd_config/test.yml 如下

- targets: [ "192.168.93.192:8080" ]
  labels:
    group: "my_test_group"

5s内就会自动读取 test.yml 并添加新的目标。
可用浏览器打开Prometheus 9090 端口,
查看 Status 中的 Configuration, Targets, Service Discovery,
可以看到新添加的目标。
posted on 2018-04-24 12:13 金庆 阅读(2210) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理