Search in sources :

Example 1 with Builder

use of org.springframework.boot.actuate.health.Health.Builder in project sofa-boot by alipay.

the class SpringContextStartUpHealthCheckStatusCheckInfo method invoke.

@Override
public Health invoke() {
    // spring
    boolean springContextStatus = StartUpHealthCheckStatus.getSpringContextStatus();
    // component
    boolean componentStatus = StartUpHealthCheckStatus.getComponentStatus();
    Map<String, Health> componentDetail = StartUpHealthCheckStatus.getComponentDetail();
    // HealthIndicator
    boolean healthIndicatorStatus = StartUpHealthCheckStatus.getHealthIndicatorStatus();
    List<HealthIndicatorDetail> healthIndicatorDetails = StartUpHealthCheckStatus.getHealthIndicatorDetails();
    // AfterHealthCheckCallback
    boolean afterHealthCheckCallbackStatus = StartUpHealthCheckStatus.getAfterHealthCheckCallbackStatus();
    Map<String, Health> afterHealthCheckCallbackDetails = StartUpHealthCheckStatus.getAfterHealthCheckCallbackDetails();
    Map<String, Health> healths = new HashMap<String, Health>();
    // spring
    if (springContextStatus) {
        healths.put("springContextHealthCheckInfo", Health.up().build());
    } else {
        healths.put("springContextHealthCheckInfo", Health.down().build());
    }
    // component and callback
    Builder builder = null;
    if (componentStatus && healthIndicatorStatus && afterHealthCheckCallbackStatus) {
        builder = Health.up();
    } else {
        builder = Health.down();
    }
    if (!CollectionUtils.isEmpty(componentDetail)) {
        builder = builder.withDetail("Middleware-start-period", componentDetail);
    }
    if (!CollectionUtils.isEmpty(afterHealthCheckCallbackDetails)) {
        builder = builder.withDetail("Middleware-operation-period", afterHealthCheckCallbackDetails);
    }
    healths.put("sofaBootComponentHealthCheckInfo", builder.build());
    // HealthIndicator
    for (HealthIndicatorDetail healthIndicatorDetail : healthIndicatorDetails) {
        String name = healthIndicatorDetail.getName();
        Health health = healthIndicatorDetail.getHealth();
        healths.put(name, health);
    }
    return this.healthAggregator.aggregate(healths);
}
Also used : Health(org.springframework.boot.actuate.health.Health) HashMap(java.util.HashMap) Builder(org.springframework.boot.actuate.health.Health.Builder) HealthIndicatorDetail(com.alipay.sofa.healthcheck.startup.StartUpHealthCheckStatus.HealthIndicatorDetail)

Example 2 with Builder

use of org.springframework.boot.actuate.health.Health.Builder in project spring-boot by spring-projects.

the class AbstractHealthIndicator method health.

@Override
public final Health health() {
    Health.Builder builder = new Health.Builder();
    try {
        doHealthCheck(builder);
    } catch (Exception ex) {
        builder.down(ex);
    }
    logExceptionIfPresent(builder.getException());
    return builder.build();
}
Also used : Builder(org.springframework.boot.actuate.health.Health.Builder) Builder(org.springframework.boot.actuate.health.Health.Builder)

Example 3 with Builder

use of org.springframework.boot.actuate.health.Health.Builder in project spring-cloud-netflix by spring-cloud.

the class EurekaHealthIndicator method health.

@Override
public Health health() {
    Builder builder = Health.unknown();
    Status status = getStatus(builder);
    return builder.status(status).withDetail("applications", getApplications()).build();
}
Also used : Status(org.springframework.boot.actuate.health.Status) Builder(org.springframework.boot.actuate.health.Health.Builder)

Aggregations

Builder (org.springframework.boot.actuate.health.Health.Builder)3 HealthIndicatorDetail (com.alipay.sofa.healthcheck.startup.StartUpHealthCheckStatus.HealthIndicatorDetail)1 HashMap (java.util.HashMap)1 Health (org.springframework.boot.actuate.health.Health)1 Status (org.springframework.boot.actuate.health.Status)1