prometheus基于json\yaml文件的target发现

1.解决的问题

  • 之前手动配置了很多个target

  • 手动配置维护成本高,还容易出错

2.基于文件的服务发现配置

链接:Configuration | Prometheus

3.特点 

  • 基于文件的服务发现提供了一种配置静态目标的更通用的方法

  • 并充当了插入自定义服务发现机制的接口。

  • 摆脱对特定服务发现源的依赖

  • 只要能正确给出 json/yaml文件即可

4.yaml文件类型

- targets:  
  - 172.20.70.205:9100
  - 172.20.70.215:9100
  labels:
    account: "huaweicloud-01"   
    region: "ap-south-1"

 

5.json文件类型

[
  {
    "targets": [
      "172.20.70.205:9100"
    ],
    "labels": {
      "account": "huaweicloud-01",
      "region": "ap-south-1",
      "env": "prod",
      "group": "inf",
      "project": "monitor",
      "stree_gpa": "inf.monitor.prometheus"
    }
  },
  {
    "targets": [
      "172.20.70.215:9100"
    ],
    "labels": {
      "account": "huaweicloud-02",
      "region": "ap-south-2",
      "env": "prod",
      "group": "inf",
      "project": "middleware",
      "stree_gpa": "inf.middleware.kafka"
    }
  }
]

  • targets 是一组实例地址的列表

  • labels 是这组实例的标签,应用到列表中所有实例

  • 如果想每个实例不同的标签,可以将targets列表保留一个实例即可

  • 标签可以自定义

  • 那么prometheus在采集对应target时就会将对应标签打入其metrics中

  • 为后续我们按照标签过滤提供方便

6.配置举例

  • files 代表 文件路径 支持通配符

  • refresh_interval 代表 文件刷新间隔

 - job_name: 'node_exporter'
    scrape_interval: 30s
    scrape_timeout: 10s
    metrics_path: /metrics
    scheme: http
    honor_timestamps: false
    file_sd_configs:
    - files:
      - /opt/app/prometheus/sd/node_exporter.json   #json或者yaml,文件自己创建
      refresh_interval: 5m

  - job_name: 'blackbox-http'
    metrics_path: /probe
    # 传入的参数
    params:
      module: [http_2xx]  # Look for a HTTP 200 response.
    scrape_interval: 15s
    scrape_timeout: 10s
    scheme: http
    honor_timestamps: false
    file_sd_configs:
    - files:
      - /opt/app/prometheus/sd/blackbox_http.json
      refresh_interval: 2m
    relabel_configs:
      - source_labels: [__address__]
        target_label: __param_target
      - source_labels: [__param_target]
        target_label: instance
      - target_label: __address__
        replacement: 172.20.70.205:9115 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值