如何 Create/Configure Spring 多个数据源的执行器?
How Do I Create/Configure Spring Actuator for Multiple Datasources?
我有一个包含多个数据源的项目,还实现了 spring 执行器。当我访问 /health 时,我得到以下信息:
{"status":"DOWN"}
这对我来说没有任何意义。什么是下来?另外,为什么缺少数据库健康状况?我假设这是因为我的数据源前缀从默认值中分叉出来。
如何配置 actuator /health 来显示两个数据源的健康状态?
其实健康端点检查的指标不止一项。您只有 {"status":"DOWN"}
,因为默认情况下 spring 启动应用程序是安全的。
您可以将 application.properties
修改为
endpoints.health.sensitive=false
显示所有健康指标。
您可以在此页面中找到所有 auto-configured 健康指标:
http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#_auto_configured_healthindicators
此外,您可以通过实施 HealthIndicator
来编写自己的健康指标。
@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();
}
}
由于此执行器现已弃用(也许这对某些人有帮助),您可以使用它:
management:
endpoint:
health:
show-details: always
我有一个包含多个数据源的项目,还实现了 spring 执行器。当我访问 /health 时,我得到以下信息:
{"status":"DOWN"}
这对我来说没有任何意义。什么是下来?另外,为什么缺少数据库健康状况?我假设这是因为我的数据源前缀从默认值中分叉出来。
如何配置 actuator /health 来显示两个数据源的健康状态?
其实健康端点检查的指标不止一项。您只有 {"status":"DOWN"}
,因为默认情况下 spring 启动应用程序是安全的。
您可以将 application.properties
修改为
endpoints.health.sensitive=false
显示所有健康指标。
您可以在此页面中找到所有 auto-configured 健康指标: http://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#_auto_configured_healthindicators
此外,您可以通过实施 HealthIndicator
来编写自己的健康指标。
@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();
}
}
由于此执行器现已弃用(也许这对某些人有帮助),您可以使用它:
management:
endpoint:
health:
show-details: always