Beans中收集到的,Spring boot框架中包含了⼤量的HealthIndicators的实现类,当然你也可以实现⾃⼰认为的健康状态。
默认情况下,最终的spring boot应⽤的状态是由HealthAggregator汇总⽽成的,汇总的算法是:
1. 设置状态码顺序:setStatusOrder(Status.DOWN, Status.OUT_OF_SERVICE, Status.UP, Status.UNKNOWN);。
2. 过滤掉不能识别的状态码。
3. 如果⽆任何状态码,整个spring boot应⽤的状态是 UNKNOWN。
4. 将所有收集到的状态码按照 1 中的顺序排序。
5. 返回有序状态码序列中的第⼀个状态码,作为整个spring boot应⽤的状态。
源代码请参见:org.springframework.boot.actuate.health.OrderedHealthAggregator。
Spring boot框架⾃带的 HealthIndicators ⽬前包括:
Name Description
CassandraHealthIndicator Checks that a Cassandra database is up.
DiskSpaceHealthIndicator Checks for low disk space.
DataSourceHealthIndicator Checks that a connection to DataSource can be obtained. ElasticsearchHealthIndicator Checks that an Elasticsearch cluster is up.
InfluxDbHealthIndicator Checks that an InfluxDB server is up.
JmsHealthIndicator Checks that a JMS broker is up.
MailHealthIndicator Checks that a mail server is up.
MongoHealthIndicator Checks that a Mongo database is up.
Neo4jHealthIndicator Checks that a Neo4j server is up.
RabbitHealthIndicator Checks that a Rabbit server is up.
RedisHealthIndicator Checks that a Redis server is up.
SolrHealthIndicator Checks that a Solr server is up.
springboot推荐算法你可以通过management.abled这个配置项将它们全部禁⽤掉,也可以通过nabled将其中任意⼀个禁⽤掉。
04 ⾃定义 HealthIndicator 健康检查
有时候需要提供⾃定义的健康状态检查信息,你可以通过实现HealthIndicator的接⼝来实现,并将该实现类注册为spring bean。你需要实现其中的health()⽅法,并返回⾃定义的健康状态响应信息,该响应信息应该包括⼀个状态码和要展⽰详细信息。例如,下⾯就是⼀个接
⼝HealthIndicator的实现类:
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论