Search in sources :

Example 1 with HealthCheckCallback

use of com.netflix.appinfo.HealthCheckCallback in project chassis by Kixeye.

the class ChassisConfiguration method healthCheckRegistry.

/**
     * Initializes the health check registry
     *
     * @return health check registry bean
     */
@Bean
public HealthCheckRegistry healthCheckRegistry(ApplicationContext context, DiscoveryManager eureka) {
    final HealthCheckRegistry bean = new HealthCheckRegistry();
    // auto-register beans implementing health checks
    Map<String, HealthCheck> healthChecks = context.getBeansOfType(HealthCheck.class);
    for (HealthCheck check : healthChecks.values()) {
        bean.register(check.getClass().getName(), check);
    }
    // connect health checks into Eureka
    if (!disableEureka) {
        eureka.getDiscoveryClient().registerHealthCheckCallback(new HealthCheckCallback() {

            @Override
            public boolean isHealthy() {
                for (Entry<String, HealthCheck.Result> entry : bean.runHealthChecks().entrySet()) {
                    if (!entry.getValue().isHealthy()) {
                        return false;
                    }
                }
                return true;
            }
        });
    }
    return bean;
}
Also used : Entry(java.util.Map.Entry) HealthCheckRegistry(com.codahale.metrics.health.HealthCheckRegistry) HealthCheck(com.codahale.metrics.health.HealthCheck) HealthCheckCallback(com.netflix.appinfo.HealthCheckCallback) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

HealthCheck (com.codahale.metrics.health.HealthCheck)1 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)1 HealthCheckCallback (com.netflix.appinfo.HealthCheckCallback)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1 Entry (java.util.Map.Entry)1 Bean (org.springframework.context.annotation.Bean)1