zoukankan      html  css  js  c++  java
  • 【Prometheus】热加载方法

    在运行时热加载Prometheus的配置信息

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

    Prometheus配置的热加载

    Prometheus配置信息的热加载有两种方式:

    第一种热加载方式:

    查看Prometheus的进程id,发送SIGHUP信号:

    kill -HUP <pid>
    

    第二种热加载方式:

    发送一个POST请求到/-/reload,需要在启动时给定--web.enable-lifecycle选项:

    curl -X POST http://localhost:9090/-/reload
    

    如果配置热加载成功,Prometheus会打印出下面的log Loading configuration file:

    Jan 11 02:48:22 proxy01 prometheus[392]: level=info ts=2021-01-11T02:48:22.215Z caller=main.go:799 msg="Loading configuration file" filena...heus.yml
    

    我们使用的是第一种热加载方式,systemd unit文件如下:

    我的 prometheus 是在 centos7 系统下面yum 安装的 rpm 包,默认是没有 ExecReload 的系统启动配置,只有 start,所以加上这一句则可。

    [root@ld_proxy01 ~]# cat /etc/systemd/system/prometheus.service

    [Unit]
    Description=Prometheus
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    User=prometheus
    Group=prometheus
    CPUAffinity=3
    Type=simple
    ExecStart=/etc/prometheus/prometheus 
        --config.file /etc/prometheus/prometheus.yml 
        --storage.tsdb.path /var/lib/prometheus/ 
        --storage.tsdb.retention.time=90d 
        --web.console.templates=/etc/prometheus/consoles 
        --web.console.libraries=/etc/prometheus/console_libraries 
        --web.external-url=http://prometheus.op.hwtech.hk:10080
    ExecReload=/bin/kill -HUP $MAINPID
    [Install]
    WantedBy=multi-user.target
    

    然后重新加载一下配置即可,一定要执行,否则会报错。

    systemctl daemon-reload
    

    在更改完/etc/prometheus/prometheus.yml之后,仅需要重新加载配置,而不需重启进程时,只需要运行以下命令即可。

    systemctl reload prometheus
    
  • 相关阅读:
    实验四 Linux系统搭建C语言编程环境
    实验三 Linux系统用户管理及VIM配置
    实验二 Linux系统简单文件操作命令
    《Linux命令行与shell脚本编程大全》勘错
    考研英语每天一段阅读理解
    仓储管理系统500bug记录一下mysql 8小时超时解决办法
    win7 64位4GB内存下 tomcat7扩大内存
    解决远程连接mysql错误1130代码的方法
    win7 64 位 tomcat 定时重启脚本
    通过Navicat for MySQL远程连接的时候报错mysql 1130
  • 原文地址:https://www.cnblogs.com/UncleZhao/p/14262043.html
Copyright © 2011-2022 走看看