spring-acturator 健康指标

1.官网

https://docs.spring.io/spring-boot/docs/2.0.0.RELEASE/reference/html/production-ready-endpoints.html#production-ready-health

2.是什么

健康指标 HealthIndicators
健康指标可用于反应正在运行的应用程序的状态

3.springboot默认检查哪些指标

指标 描述
CassandraHealthIndicator 检查Cassandra数据库是否已启动。
DiskSpaceHealthIndicator 检查磁盘空间不足。
DataSourceHealthIndicator 检查是否可以获得连接DataSource。
ElasticsearchHealthIndicator 检查Elasticsearch集群是否已启动。
InfluxDbHealthIndicator 检查InfluxDB服务器是否已启动。
JmsHealthIndicator 检查JMS代理是否已启动。
MailHealthIndicator 检查邮件服务器是否已启动。
MongoHealthIndicator 检查Mongo数据库是否已启动。
Neo4jHealthIndicator 检查Neo4j服务器是否已启动。
RabbitHealthIndicator 检查Rabbit服务器是否已启动。
RedisHealthIndicator 检查Redis服务器是否已启动。
SolrHealthIndicator 检查Solr服务器是否已启动。

4.如何禁用这些指标

全部禁用
management:
  health:
    default:
      enabled: false
禁用部分
management:
  health:
    db:
      enabled: false
    diskspace:
      enabled: false

5.如何自定义指标

import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class MyHealthIndicator implements HealthIndicator {
    @Override
    public Health health() {
        int errorCode = check(); // perform some specific health check
        if (errorCode != 0) {
            return Health.down().withDetail("Error Code", errorCode).build();
        }
        return Health.up().build();
    }
} 

猜你喜欢

转载自blog.csdn.net/huiyanshizhen21/article/details/89513166