![]()
简介
之前碰到过一个神奇的问题,就是不然怎么请求prometheus的reload接口,prometheus的配置文件就是不能重载,以至于让我对这个世界失去了信息
操作
我是使用docker搭建的prometheus,这也是问题的关键,下面是我的compose文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| version: "3" services: prometheus: image: "prom/prometheus:v2.14.0" container_name: "prometheus" restart: "always" ports: - "9000:9000" - "9090:9090" volumes: - "./prometheus.yml:/etc/prometheus/prometheus.yml" - "./prometheus-data:/prometheus" - "/etc/localtime:/etc/localtime" - "./hostsconf:/etc/prometheus/hostsconf" - "./rules:/etc/prometheus/rules" command: - "--config.file=/etc/prometheus/prometheus.yml" - "--web.enable-admin-api" - "--web.enable-lifecycle"
|
看着没问题对吧,的确是没问题
1 2
| - "--web.enable-admin-api" - "--web.enable-lifecycle"
|
这两行也是没有问题的,官方文档说这样就可以使用reload接口了
curl -XPOST http://127.0.0.1:9090/-/reload
看下日志
1 2
| level=info ts=2020-04-08T08:06:40.948Z caller=main.go:743 msg="Loading configuration file" filename=/etc/prometheus/prometheus.yml level=info ts=2020-04-08T08:06:40.950Z caller=main.go:771 msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml
|
发现接口请求是正常执行的
但是当你修改主机外部的prometheus.yml配置文件之后进入容器中cat下prometheus.yml,发现容器中的prometheus.yml并没有修改
编辑说是只读的,所以问题很显然是文件的权限问题,修改prometheus.yml的权限之后重新启动容器就可以了
之后看下官方的dockerfile
1 2
| RUN mkdir -p /prometheus && \ chown -R nobody:nogroup etc/prometheus /prometheus
|
真相了
欢迎关注我的博客www.bboy.app
Have Fun