Search in sources :

Example 1 with HealthIndicator

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());
}
Also used : HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) HealthChecker(com.alipay.sofa.healthcheck.core.HealthChecker)

Example 2 with HealthIndicator

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;
}
Also used : Status(org.springframework.boot.actuate.health.Status) StartUpHealthCheckStatus(com.alipay.sofa.healthcheck.startup.StartUpHealthCheckStatus) HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) Health(org.springframework.boot.actuate.health.Health) HealthIndicatorDetail(com.alipay.sofa.healthcheck.startup.StartUpHealthCheckStatus.HealthIndicatorDetail)

Example 3 with HealthIndicator

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);
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) ConditionalOnEnabledHealthIndicator(org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) MongoDbHealthIndicator(org.apereo.cas.monitor.MongoDbHealthIndicator) MongoDbConnectionFactory(org.apereo.cas.mongo.MongoDbConnectionFactory) lombok.val(lombok.val) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) CasMongoOperations(org.apereo.cas.mongo.CasMongoOperations) HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) Collectors(java.util.stream.Collectors) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Configuration(org.springframework.context.annotation.Configuration) BeanContainer(org.apereo.cas.util.spring.beans.BeanContainer) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) CasSSLContext(org.apereo.cas.authentication.CasSSLContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) CompositeHealthIndicator(org.apereo.cas.monitor.CompositeHealthIndicator) Bean(org.springframework.context.annotation.Bean) CompositeHealthIndicator(org.apereo.cas.monitor.CompositeHealthIndicator) MongoDbHealthIndicator(org.apereo.cas.monitor.MongoDbHealthIndicator) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnEnabledHealthIndicator(org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with HealthIndicator

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");
}
Also used : DataSourceHealthIndicator(org.springframework.boot.actuate.health.DataSourceHealthIndicator) CompositeHealthIndicator(org.springframework.boot.actuate.health.CompositeHealthIndicator) CassandraHealthIndicator(org.springframework.boot.actuate.health.CassandraHealthIndicator) SolrHealthIndicator(org.springframework.boot.actuate.health.SolrHealthIndicator) ElasticsearchJestHealthIndicator(org.springframework.boot.actuate.health.ElasticsearchJestHealthIndicator) CouchbaseHealthIndicator(org.springframework.boot.actuate.health.CouchbaseHealthIndicator) LdapHealthIndicator(org.springframework.boot.actuate.health.LdapHealthIndicator) ElasticsearchHealthIndicator(org.springframework.boot.actuate.health.ElasticsearchHealthIndicator) ApplicationHealthIndicator(org.springframework.boot.actuate.health.ApplicationHealthIndicator) RedisHealthIndicator(org.springframework.boot.actuate.health.RedisHealthIndicator) MailHealthIndicator(org.springframework.boot.actuate.health.MailHealthIndicator) DiskSpaceHealthIndicator(org.springframework.boot.actuate.health.DiskSpaceHealthIndicator) HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) RabbitHealthIndicator(org.springframework.boot.actuate.health.RabbitHealthIndicator) MongoHealthIndicator(org.springframework.boot.actuate.health.MongoHealthIndicator) JmsHealthIndicator(org.springframework.boot.actuate.health.JmsHealthIndicator) DataSourceHealthIndicator(org.springframework.boot.actuate.health.DataSourceHealthIndicator) Test(org.junit.Test)

Example 5 with HealthIndicator

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");
}
Also used : CompositeHealthIndicator(org.springframework.boot.actuate.health.CompositeHealthIndicator) CassandraHealthIndicator(org.springframework.boot.actuate.health.CassandraHealthIndicator) SolrHealthIndicator(org.springframework.boot.actuate.health.SolrHealthIndicator) ElasticsearchJestHealthIndicator(org.springframework.boot.actuate.health.ElasticsearchJestHealthIndicator) CouchbaseHealthIndicator(org.springframework.boot.actuate.health.CouchbaseHealthIndicator) LdapHealthIndicator(org.springframework.boot.actuate.health.LdapHealthIndicator) ElasticsearchHealthIndicator(org.springframework.boot.actuate.health.ElasticsearchHealthIndicator) ApplicationHealthIndicator(org.springframework.boot.actuate.health.ApplicationHealthIndicator) RedisHealthIndicator(org.springframework.boot.actuate.health.RedisHealthIndicator) MailHealthIndicator(org.springframework.boot.actuate.health.MailHealthIndicator) DiskSpaceHealthIndicator(org.springframework.boot.actuate.health.DiskSpaceHealthIndicator) HealthIndicator(org.springframework.boot.actuate.health.HealthIndicator) RabbitHealthIndicator(org.springframework.boot.actuate.health.RabbitHealthIndicator) MongoHealthIndicator(org.springframework.boot.actuate.health.MongoHealthIndicator) JmsHealthIndicator(org.springframework.boot.actuate.health.JmsHealthIndicator) DataSourceHealthIndicator(org.springframework.boot.actuate.health.DataSourceHealthIndicator) Test(org.junit.Test)

Aggregations

HealthIndicator (org.springframework.boot.actuate.health.HealthIndicator)7 Test (org.junit.Test)3 CompositeHealthIndicator (org.springframework.boot.actuate.health.CompositeHealthIndicator)3 ApplicationHealthIndicator (org.springframework.boot.actuate.health.ApplicationHealthIndicator)2 CassandraHealthIndicator (org.springframework.boot.actuate.health.CassandraHealthIndicator)2 CouchbaseHealthIndicator (org.springframework.boot.actuate.health.CouchbaseHealthIndicator)2 DataSourceHealthIndicator (org.springframework.boot.actuate.health.DataSourceHealthIndicator)2 DiskSpaceHealthIndicator (org.springframework.boot.actuate.health.DiskSpaceHealthIndicator)2 ElasticsearchHealthIndicator (org.springframework.boot.actuate.health.ElasticsearchHealthIndicator)2 ElasticsearchJestHealthIndicator (org.springframework.boot.actuate.health.ElasticsearchJestHealthIndicator)2 JmsHealthIndicator (org.springframework.boot.actuate.health.JmsHealthIndicator)2 LdapHealthIndicator (org.springframework.boot.actuate.health.LdapHealthIndicator)2 MailHealthIndicator (org.springframework.boot.actuate.health.MailHealthIndicator)2 MongoHealthIndicator (org.springframework.boot.actuate.health.MongoHealthIndicator)2 RabbitHealthIndicator (org.springframework.boot.actuate.health.RabbitHealthIndicator)2 RedisHealthIndicator (org.springframework.boot.actuate.health.RedisHealthIndicator)2 SolrHealthIndicator (org.springframework.boot.actuate.health.SolrHealthIndicator)2 HealthChecker (com.alipay.sofa.healthcheck.core.HealthChecker)1 SofaBootComponentHealthCheckInfo (com.alipay.sofa.healthcheck.service.SofaBootComponentHealthCheckInfo)1 SpringContextHealthCheckInfo (com.alipay.sofa.healthcheck.service.SpringContextHealthCheckInfo)1