prometheus基于文件自动发现
  tU1ziTlGSBCW 2023年11月02日 35 0

基于文件发现不需要重启或热加载peometheus

----prometheus.yml

# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "first_rules.yml"
  # - "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"
    file_sd_configs:
    - refresh_interval: 10s
      files:
      - "targets/target.yml"
  - job_name: "node_exporter"
    file_sd_configs:
    - refresh_interval: 10s     #每隔十秒读取一次文件
      files:
      - "targets/node_exporter.yml"
  - job_name: "pushgateway"
    file_sd_configs:
    - refresh_interval: 10s
      files:
      - "targets/pushgateway.yml"
[root@localhost targets]# pwd
/opt/prometheus/targets
[root@localhost targets]# ls
node_exporter.yml  pushgateway.yml  target.yml
[root@localhost targets]# cat node_exporter.yml 
- targets: ['192.168.49.217:9100']
  labels:
    job: node_exporter
[root@localhost targets]# cat pushgateway.yml 
- targets: ['192.168.49.217:9091']
  labels:
    job: pushgateway
[root@localhost targets]# cat target.yml 
- targets: ['192.168.49.217:9090']
  labels:
    job: prometheus

配置完重启peometheus正常运行后修改对应服务的文件

--添加标签测试

[root@localhost targets]# cat target.yml 
- targets: ['192.168.49.217:9090']
  labels:
    job: prometheus
    env: test

可以看到web端自动展示新添加的标签

prometheus基于文件自动发现_prometheus

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  CXvnc1NhAWTQ   2023年11月13日   34   0   0 PrometheusAlertManager
  yx99X8RMvAE0   2023年11月02日   70   0   0 Prometheus
  zNxK8cIqmu7p   2023年11月02日   39   0   0 Prometheus