• prometheus基于文件发现及热加载


    Promtheus的时序数据库在存储了大量的数据后,每次重启Prometheus进程的时间会越来越慢。 而在日常运维工作中会经常调整Prometheus的配置信息。
    Prometheus提供了在运行时热加载配置信息的功能。

    1. 查看Prometheus的进程id,发送 SIGHUP 信号
    2. 发送一个POST请求到 /-/reload ,需要在启动时给定 --web.enable-lifecycle 选项
      prometheus支持服务发现(也是运维最佳实践经常采用的):
    • file_sd_configs
    • azure_sd_configs
    • consul_sd_configs
    • dns_sd_configs
    • ec2_sd_configs
    • openstack_sd_configs
    • gce_sd_configs
    • kubernetes_sd_configs
    • marathon_sd_configs
    • nerve_sd_configs
    • serverset_sd_configs
    • triton_sd_configs

    参考

    Prometheus、Grafana安装-部署-nginx代理-监控linux
    详解Prometheus自动发现之file_sd_config
    Prometheus 基于文件的服务发现 file_sd_configs
    Prometheus之配置详解
    Prometheus配置的热加载

    操作

    基于文件发现

    原配置

    # 增加监控节点
      - job_name: "centos7_test"
        static_configs:
          - targets: ["127.0.0.1:9100"]
    # 增加应用检测节点
      - job_name: "springBoot-ecb-t"
        metrics_path: "/ecb/actuator/prometheus"
        static_configs:
          - targets: ["127.0.0.1:9521"]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    本次基于yml文件维护子配置信息

    cd /usr/local/prometheus/
    ll
    # 创建父目录及多个子目录
    mkdir -p file_sd/{test,prod}
    # 创建 子配置
    vim file_sd/test/node.yml
    cat file_sd/test/node.yml 
    ###
    - targets: ['127.0.0.1:9100']
    ###
    vim file_sd/test/spring-boots.yml
    cat file_sd/test/spring-boots.yml 
    ###
    - targets: ['127.0.0.1:9521']
    ###
    chown -R prometheus.prometheus file_sd
    vim prometheus.yml
    ###
    scrape_configs:
      - job_name: "prometheus"
        metrics_path: "/prometheus/metrics"
        static_configs:
          - targets: ["127.0.0.1:9090"]
    # 增加监控节点
      - job_name: "centos7_test"
        #static_configs:
        #  - targets: ["127.0.0.1:9100"]
        file_sd_configs:
          - files: ['file_sd/test/node.yml']
    # 增加应用检测节点
      - job_name: "springBoot-ecb-t"
        metrics_path: "/ecb/actuator/prometheus"
        #static_configs:
        #  - targets: ["127.0.0.1:9521"]
        file_sd_configs:
          - files: ['/usr/local/prometheus/file_sd/test/spring-boots.yml']
          refresh_interval: 60s
    ###
    ./promtool check config prometheus.yml
    ###
    Checking prometheus.yml
     SUCCESS: prometheus.yml is valid prometheus config file syntax
    ###
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    通过热加载,重新加载配置

    热加载

    curl -X POST http://localhost:9090/prometheus/-/reload
    
    • 1

    访问验证

    地址:http://192.168.xxx.xxx:9090/prometheus/service-discovery?search=
    在这里插入图片描述

    END

  • 相关阅读:
    中间件、Kafka、Zookeeper
    Java Object 类
    华为OD机考:0036-0037-最多组团数--作业总时长
    YUV转RGB888
    tensorflow2.x --------------------DenseNet-----------------------------
    零数科技携手云南能投智慧打造全国最大区块链实体项目
    在 C# CLR 中学习 C++ 之了解 extern
    Leetcode 1089. 复写零
    023 gtsam/examples/RangeISAMExample_plaza2.cpp
    leetcode:32. 最长有效括号
  • 原文地址:https://blog.csdn.net/privateobject/article/details/126381386