Prometheusの設定ファイルを変更させた時に、Prometheusのプロセスを再起動することなく設定ファイルをリロードさせるには、
HUPシグナルを送ればよいみたいです。
確認したバージョンは、Prometheus 2.7.1です。
A configuration reload is triggered by sending a SIGHUP to the Prometheus process
以下のように、Prometheusのプロセスに対して、SIGHUPを送ると
$ kill -HUP [PID] $ kill -1 [PID]
以下のようにログが出力されます。
level=info ts=2019-02-09T13:30:46.085041159Z caller=main.go:695 msg="Loading configuration file" filename=prometheus.yml level=info ts=2019-02-09T13:30:46.085706797Z caller=main.go:722 msg="Completed loading of configuration file" filename=prometheus.yml
これで、設定がリロードされます。
なお、構文が誤った設定ファイルを再読み込みさせたりしても、特にプロセスがダウンするといったようなことはなさそうです。
例えば、YAMLの配列の閉じ括弧を忘れたとか。
level=info ts=2019-02-09T13:33:12.628537866Z caller=main.go:695 msg="Loading configuration file" filename=prometheus.yml level=error ts=2019-02-09T13:33:12.628881835Z caller=main.go:546 msg="Error reloading config" err="couldn't load configuration (--config.file=\"prometheus.yml\"): parsing YAML file prometheus.yml: yaml: line 33: did not find expected ',' or ']'"
あと、「/-/reload」エンドポイントにPOSTすることでも、設定ファイルをリロードできます。
sending a HTTP POST request to the /-/reload endpoint (when the --web.enable-lifecycle flag is enabled).
ですが、この機能を使うにはPrometheusの起動時に「--web.enable-lifecycle」を有効にしておく必要があります。
「--web.enable-lifecycle」フラグを有効にしていないと、以下のようにリクエストを拒否されます。
$ curl -i -XPOST localhost:9090/-/reload HTTP/1.1 403 Forbidden Date: Sat, 09 Feb 2019 13:41:08 GMT Content-Length: 30 Content-Type: text/plain; charset=utf-8 Lifecycle APIs are not enabled
このように、「--web.enable-lifecycle」フラグをPrometheusnの起動時につけておくと、「/-/reload」エンドポイントにPOSTすることで
設定ファイルのリロードができるようになります。
$ ./prometheus --web.enable-lifecycle
「/-/reload」エンドポイントの呼び出しに成功した場合は、特になにも返ってきません。
$ curl -i -XPOST localhost:9090/-/reload HTTP/1.1 200 OK Date: Sat, 09 Feb 2019 13:40:11 GMT Content-Length: 0