Spring Boot Actuator - Multiple Health Endpoints

ε祈祈猫儿з 提交于 2021-02-18 15:02:09

问题


Is there any way to support multiple health endpoints on a Spring Boot application?

Here's why: The standard actuator health check is great, built in checks are great, customization options are great - for a single use case: reporting on general application health.

But I'd like something I can call from an AWS Elastic Load Balancer / AutoScaling Group. By default, if an instance fails a health check, the ELB/ASG will terminate it and replace it with a fresh instance. The problem is some of the health checks, like DataSourceHealthIndicator, will report DOWN if the database is down, but my application instance is otherwise perfectly healthy. If I use the default behavior, AWS will throw out perfectly healthy instances until the database comes back up, and this will run up my bill.

I could get rid of the DataSourceHealthIndicator, but I like having it around for general health checking purposes. So what I really want is two separate endpoints for two different purposes, such as:

/health - General application health /ec2Health - Ignores aspects unrelated to the EC2 instance, such as a DB outage.

Hope that makes sense.


回答1:


Spring Boot Actuator has a feature called Health Groups which allows you to configure multiple health indicators.

In application.properties you configure the groups that you want:

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

Output:

$ 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"}}}


来源:https://stackoverflow.com/questions/55522987/spring-boot-actuator-multiple-health-endpoints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!