use of org.springframework.boot.actuate.health.HealthIndicator in project sofa-boot by alipay.
the class HealthCheckTrigger method logPrintCheckers.
private void logPrintCheckers() {
List<HealthChecker> healthCheckers = HealthCheckManager.getHealthCheckers();
List<HealthIndicator> healthIndicators = HealthCheckManager.getHealthIndicator();
StringBuilder hcInfo = new StringBuilder();
hcInfo.append("\nFound " + healthCheckers.size() + " component health checkers:").append("\n");
for (HealthChecker healthchecker : healthCheckers) {
hcInfo.append(healthchecker.getClass()).append("\n");
}
hcInfo.append("Found " + healthIndicators.size() + " indicator health checkers:").append("\n");
for (HealthIndicator healthIndicator : healthIndicators) {
hcInfo.append(healthIndicator.getClass()).append("\n");
}
logger.info(hcInfo.toString());
}
use of org.springframework.boot.actuate.health.HealthIndicator in project sofa-boot by alipay.
the class HealthIndicatorCheckProcessor method checkIndicator.
public boolean checkIndicator() {
if (skipHealthIndicator()) {
logger.info("Skip startup healthIndicator check.");
return true;
}
logger.info("Begin startup healthIndicator check.");
List<HealthIndicator> healthIndicators = HealthCheckManager.getHealthIndicator();
if (healthIndicators == null) {
return true;
}
boolean result = true;
for (HealthIndicator healthIndicator : healthIndicators) {
try {
Health health = healthIndicator.health();
Status status = health.getStatus();
if (!status.equals(Status.UP)) {
result = false;
logger.error("healthIndicator (" + healthIndicator.getClass() + ")check fail. And the status is[" + status + "]; the detail is: " + JSON.toJSONString(health.getDetails()));
} else {
logger.info("healthIndicator (" + healthIndicator.getClass() + ")check success.");
}
StartUpHealthCheckStatus.addHealthIndicatorDetail(new HealthIndicatorDetail(getKey(healthIndicator), health));
} catch (Exception e) {
result = false;
logger.error("Error occurred while doing healthIndicator health check(" + healthIndicator.getClass() + ")", e);
}
}
if (result) {
logger.info("Startup healthIndicator check result: success.");
} else {
logger.error("Startup healthIndicator check result: fail.");
}
StartUpHealthCheckStatus.setHealthIndicatorStatus(result);
return result;
}
use of org.springframework.boot.actuate.health.HealthIndicator in project cas by apereo.
the class MongoDbMonitoringConfiguration method mongoHealthIndicator.
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
@ConditionalOnEnabledHealthIndicator("mongoHealthIndicator")
@ConditionalOnMissingBean(name = "mongoHealthIndicator")
public HealthIndicator mongoHealthIndicator(final CasConfigurationProperties casProperties, @Qualifier("mongoHealthIndicatorTemplate") final BeanContainer<CasMongoOperations> mongoHealthIndicatorTemplate) {
val warn = casProperties.getMonitor().getWarn();
val results = mongoHealthIndicatorTemplate.toList().stream().map(template -> new MongoDbHealthIndicator(template, warn.getEvictionThreshold(), warn.getThreshold())).collect(Collectors.toList());
return new CompositeHealthIndicator(results);
}
use of org.springframework.boot.actuate.health.HealthIndicator in project spring-boot by spring-projects.
the class HealthIndicatorAutoConfigurationTests method dataSourceHealthIndicatorWithCustomValidationQuery.
@Test
public void dataSourceHealthIndicatorWithCustomValidationQuery() {
this.context.register(PropertyPlaceholderAutoConfiguration.class, ManagementServerProperties.class, DataSourceProperties.class, DataSourceConfig.class, DataSourcePoolMetadataProvidersConfiguration.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "spring.datasource.test.validation-query:SELECT from FOOBAR", "management.health.diskspace.enabled:false");
this.context.refresh();
Map<String, HealthIndicator> beans = this.context.getBeansOfType(HealthIndicator.class);
assertThat(beans).hasSize(1);
HealthIndicator healthIndicator = beans.values().iterator().next();
assertThat(healthIndicator.getClass()).isEqualTo(DataSourceHealthIndicator.class);
DataSourceHealthIndicator dataSourceHealthIndicator = (DataSourceHealthIndicator) healthIndicator;
assertThat(dataSourceHealthIndicator.getQuery()).isEqualTo("SELECT from FOOBAR");
}
use of org.springframework.boot.actuate.health.HealthIndicator in project spring-boot by spring-projects.
the class HealthIndicatorAutoConfigurationTests method dataSourceHealthIndicatorWithSeveralDataSources.
@Test
public void dataSourceHealthIndicatorWithSeveralDataSources() {
this.context.register(EmbeddedDataSourceConfiguration.class, DataSourceConfig.class, ManagementServerProperties.class, HealthIndicatorAutoConfiguration.class);
EnvironmentTestUtils.addEnvironment(this.context, "management.health.diskspace.enabled:false");
this.context.refresh();
Map<String, HealthIndicator> beans = this.context.getBeansOfType(HealthIndicator.class);
assertThat(beans).hasSize(1);
HealthIndicator bean = beans.values().iterator().next();
assertThat(bean).isExactlyInstanceOf(CompositeHealthIndicator.class);
assertThat(bean.health().getDetails()).containsOnlyKeys("dataSource", "testDataSource");
}
Aggregations