Promtheus的时序数据库在存储了大量的数据后,每次重启Prometheus进程的时间会越来越慢。 而在日常运维工作中会经常调整Prometheus的配置信息。
Prometheus提供了在运行时热加载配置信息的功能。
- 查看Prometheus的进程id,发送 SIGHUP 信号
- 发送一个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"]
本次基于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
###
通过热加载,重新加载配置
热加载
curl -X POST http://localhost:9090/prometheus/-/reload
访问验证
地址:http://192.168.xxx.xxx:9090/prometheus/service-discovery?search=