在執行時熱載入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:
... msg="Loading configuration file" filename=prometheus.yml ...
我們使用的是第一種熱載入方式,systemd unit檔案如下:
[Unit] Description=prometheus After=network.target [Service] Type=simple User=prometheus ExecStart=/usr/local/prometheus/prometheus \ --config.file==/usr/local/prometheus/prometheus.yml \ --storage.tsdb.path=/home/prometheus/data \ --storage.tsdb.retention=365d \ --web.listen-address=:9090 \ --web.external-url=https://prometheus.frognew.com ExecReload=/bin/kill -HUP $MAINPID Restart=on-failure [Install] WantedBy=multi-user.target
在僅需要重新載入配置,而不需重啟程序時,只需要執行systemctl reload prometheus
即可。