问题描述
有什么方法可以在Spring Boot应用程序上支持多个运行状况终结点吗?
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.
但是我想要可以从AWS Elastic Load Balancer/AutoScaling组调用的内容.默认情况下,如果实例未通过运行状况检查,则ELB/ASG将终止该实例,并用新实例替换它.问题是某些运行状况检查(例如DataSourceHealthIndicator)将在数据库关闭时报告DOWN,但是我的应用程序实例运行状况良好.如果我使用默认行为,AWS将丢弃运行状况良好的实例,直到备份数据库为止,这将增加我的账单.
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.
我可以摆脱DataSourceHealthIndicator,但我喜欢为了一般的健康检查而使用它.所以我真正想要的是两个单独的端点,用于两个不同的目的,例如:
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-常规应用程序健康/ec2Health-忽略与EC2实例无关的方面,例如数据库中断.
/health - General application health/ec2Health - Ignores aspects unrelated to the EC2 instance, such as a DB outage.
希望如此.
推荐答案
Spring Boot Actuator具有称为运行状况组,通过它可以配置多个运行状况指示器.
Spring Boot Actuator has a feature called Health Groups which allows you to configure multiple health indicators.
在application.properties中,配置所需的组:
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
输出:
$ 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"}}}
这篇关于Spring Boot执行器-多个运行状况端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!