我正在使用Spring boot Actuator API进行健康检查端点,并通过以下方式启用了它:
management.endpoints.web.base-path=/
management.endpoints.web.path-mapping.health=healthcheck
此处提到:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-monitoring.html
现在,当上述运行状况检查的状态失败时,我想在我的应用程序日志文件中启用日志,并从该端点打印整个响应。
您能帮忙还是建议实现此目的的正确方法?
答案 0 :(得分:0)
答案 1 :(得分:0)
如果使用 Webflux,这对我在 Kotlin 中的示例有用
@Component
@EndpointWebExtension(endpoint = HealthEndpoint::class)
class LoggingReactiveHealthEndpointWebExtension(
registry: ReactiveHealthContributorRegistry,
groups: HealthEndpointGroups
) : ReactiveHealthEndpointWebExtension(registry, groups) {
companion object {
private val logger = LoggerFactory.getLogger(LoggingReactiveHealthEndpointWebExtension::class.java)
}
override fun health(
apiVersion: ApiVersion?,
securityContext: SecurityContext?,
showAll: Boolean,
vararg path: String?
): Mono<WebEndpointResponse<out HealthComponent>> {
val health = super.health(apiVersion, securityContext, showAll, *path)
return health.doOnNext {
if (it.body.status == UP) {
logger.info("Health status: {}, {}", it.body.status, ObjectMapper().writeValueAsString(it.body))
}
}
}
}