【问题标题】:Spring Boot Actuator - Multiple Health EndpointsSpring Boot Actuator - 多个健康端点
【发布时间】:2020-07-08 04:46:46
【问题描述】:

有什么方法可以在 Spring Boot 应用程序上支持多个健康端点?

原因如下:标准执行器健康检查非常棒,内置检查非常棒,自定义选项非常棒 - 对于单个用例:报告一般应用程序健康状况。

但我想从 AWS Elastic Load Balancer / AutoScaling Group 调用一些东西。默认情况下,如果实例未通过健康检查,ELB/ASG 将终止它并用新实例替换它。问题是一些健康检查,如 DataSourceHealthIndicator,如果数据库关闭,将报告 DOWN,但我的应用程序实例在其他方面非常健康。如果我使用默认行为,AWS 将抛出完全健康的实例,直到数据库恢复正常,这将增加我的账单。

我可以摆脱 DataSourceHealthIndicator,但我喜欢将它用于一般健康检查目的。所以我真正想要的是两个不同的端点用于两个不同的目的,例如:

/health - 一般应用程序运行状况 /ec2Health - 忽略与 EC2 实例无关的方面,例如数据库中断。

希望这是有道理的。

【问题讨论】:

  • 你用的是什么版本的spring boot?如果您只想检查应用程序是否能够响应 HTTP 请求并且其外部资源都没有下降,那么编写自己的运行状况检查相当简单

标签: spring-boot amazon-elb spring-boot-actuator


【解决方案1】:

Spring Boot Actuator 有一个名为 Health Groups 的功能,可让您配置多个运行状况指标。

在 application.properties 中配置所需的组:

management.endpoints.web.path-mapping.health=probes

management.endpoint.health.group.health.include=*
management.endpoint.health.group.health.show-details=never

management.endpoint.health.group.detail.include=*
management.endpoint.health.group.detail.show-details=always

management.endpoint.health.group.other.include=diskSpace,ping
management.endpoint.health.group.other.show-details=always

输出:

$ curl http://localhost:8080/actuator/probes
{"status":"UP","groups":["detail","health","other"]}

$ curl http://localhost:8080/actuator/probes/health
{"status":"UP"}

$ curl http://localhost:8080/actuator/probes/detail
{"status":"UP","components":{"diskSpace":{"status":"UP","details":{"total":0,"free":0,"threshold":0,"exists":true}},"ping":{"status":"UP"},"rabbit":{"status":"UP","details":{"version":"3.6.16"}}}}

$ curl http://localhost:8080/actuator/probes/other
{"status":"UP","components":{"diskSpace":{"status":"UP","details":{"total":0,"free":0,"threshold":0,"exists":true}},"ping":{"status":"UP"}}}

【讨论】:

  • 我会根据所包含的内容获得不同的 UP / DOWN 结果吗?这看起来像是一种基本的查询/过滤机制,而不是会以不同方式评估健康状况的东西。
  • 是的,根据您的选择,您会得到不同的结果。我认为您选择的所有内容都需要健康,以便聚合指标返回"UP"。例如,health 可以是 "DOWN" 由于数据库中断,但如果您的本地磁盘空间很好,other(在我的示例中)仍然可以返回 "UP"
猜你喜欢
  • 2023-03-10
  • 2015-12-06
  • 1970-01-01
  • 2023-03-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-05-29
  • 1970-01-01
相关资源
最近更新 更多