feat(metrics): 运行指标服务端支持设置 HTTP 认证.

支持对运行指标服务端设置 HTTP 认证, 以防止运行指标被非法获取.
This commit is contained in:
2022-06-18 09:20:46 +08:00
parent c5fe96c02d
commit 215a4670db
4 changed files with 187 additions and 7 deletions

View File

@ -39,14 +39,15 @@ fun main(args: Array<String>): Unit = runBlocking {
* 启动运行指标服务器.
* 使用 Prometheus 指标格式.
*/
internal fun startMetricsServer(config: MetricsConfig = Const.config.metrics) {
internal fun startMetricsServer(config: MetricsConfig = Const.config.metrics): HTTPServer? {
if (!config.enable) {
log.debug { "运行指标服务器已禁用." }
return
return null
}
val builder = HTTPServer.Builder()
.withDaemonThreads(true)
.withAuthenticator(config.authenticator)
.withPort(config.port)
.withHostname(config.bindAddress)
@ -54,6 +55,7 @@ internal fun startMetricsServer(config: MetricsConfig = Const.config.metrics) {
.build()
.registerShutdownHook()
log.info { "运行指标服务器已启动. (Port: ${httpServer.port})" }
return httpServer
}
internal class Launcher(private val config: AppConfig = Const.config) : AutoCloseable {