1. 方法1:
用 pgrep -f prometheus
找到运行的 Prometheus 进程号
使用 kill-TERM 1234
来关闭
2. 方法2
需要通过 --web.enable-lifecycle 参数开启 lifecycle 功能,Prometheus 提供了 HTTP 关闭接口,开启后,然后你就可以使用 HTTP 请求来关闭程序了
curl -X POST http://localhost:9090/-/quit
优雅关闭具体执行流程:
level=warn ts=2018-06-26T03:37:35.209100753Z caller=main.go:381 msg="Received termination request via web service, exiting gracefully..."
level=info ts=2018-06-26T03:37:35.212894277Z caller=main.go:402 msg="Stopping scrape discovery manager..."
level=info ts=2018-06-26T03:37:35.212937719Z caller=main.go:416 msg="Stopping notify discovery manager..."
level=info ts=2018-06-26T03:37:35.212963663Z caller=main.go:438 msg="Stopping scrape manager..."
level=info ts=2018-06-26T03:37:35.212975269Z caller=main.go:398 msg="Scrape discovery manager stopped"
level=info ts=2018-06-26T03:37:35.213029699Z caller=main.go:412 msg="Notify discovery manager stopped"
level=info ts=2018-06-26T03:37:35.21332349Z caller=main.go:432 msg="Scrape manager stopped"
level=info ts=2018-06-26T03:37:35.237387659Z caller=manager.go:464 component="rule manager" msg="Stopping rule manager..."
level=info ts=2018-06-26T03:37:35.238240277Z caller=manager.go:470 component="rule manager" msg="Rule manager stopped"
level=info ts=2018-06-26T03:37:35.238625599Z caller=notifier.go:512 component=notifier msg="Stopping notification manager..."
level=info ts=2018-06-26T03:37:35.238693489Z caller=main.go:588 msg="Notifier manager stopped"
level=info ts=2018-06-26T03:37:35.238723167Z caller=main.go:599 msg="See you next time!"
在程序终止之前它依次关闭了如下服务:
-
scrape discovery manager
-
notify discovery manager
-
scrape manager
-
rule manager
-
notification manager
-
fanoutStorage
优雅关闭 Prometheus 耗时较长,请安心等待,它在关闭的同时做了很多依赖服务的清理工作,其中最主要的就是 fanoutStorage,如果它没有正常关闭,很有可能破坏 TSDB 正在落盘的数据,从而导致一些莫名的 bug,以至于再也无法启动 Prometheus