use of com.codahale.metrics.health.HealthCheckRegistry in project chassis by Kixeye.
the class MetricsConfiguration method healthCheckRegistry.
/**
* Initializes the health check registry
*
* @return health check registry bean
*/
@Bean
public HealthCheckRegistry healthCheckRegistry(ApplicationContext context) {
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);
}
return bean;
}
use of com.codahale.metrics.health.HealthCheckRegistry in project metrics by dropwizard.
the class HealthCheckServletTest method constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig.
@Test
public void constructorWithRegistryAsArgumentIsUsedInPreferenceOverServletConfig() throws Exception {
final HealthCheckRegistry healthCheckRegistry = mock(HealthCheckRegistry.class);
final ServletContext servletContext = mock(ServletContext.class);
final ServletConfig servletConfig = mock(ServletConfig.class);
when(servletConfig.getServletContext()).thenReturn(servletContext);
final io.dropwizard.metrics.servlets.HealthCheckServlet healthCheckServlet = new io.dropwizard.metrics.servlets.HealthCheckServlet(healthCheckRegistry);
healthCheckServlet.init(servletConfig);
verify(servletConfig, times(1)).getServletContext();
verify(servletContext, never()).getAttribute(eq(io.dropwizard.metrics.servlets.HealthCheckServlet.HEALTH_CHECK_REGISTRY));
}
use of com.codahale.metrics.health.HealthCheckRegistry in project metrics by dropwizard.
the class HealthCheckServletTest method constructorWithRegistryAsArgumentUsesServletConfigWhenNull.
@Test
public void constructorWithRegistryAsArgumentUsesServletConfigWhenNull() throws Exception {
final HealthCheckRegistry healthCheckRegistry = mock(HealthCheckRegistry.class);
final ServletContext servletContext = mock(ServletContext.class);
final ServletConfig servletConfig = mock(ServletConfig.class);
when(servletConfig.getServletContext()).thenReturn(servletContext);
when(servletContext.getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY)).thenReturn(healthCheckRegistry);
final HealthCheckServlet healthCheckServlet = new HealthCheckServlet(null);
healthCheckServlet.init(servletConfig);
verify(servletConfig, times(1)).getServletContext();
verify(servletContext, times(1)).getAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY);
}
use of com.codahale.metrics.health.HealthCheckRegistry 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;
}
use of com.codahale.metrics.health.HealthCheckRegistry in project tutorials by eugenp.
the class HealthCheckIntegrationTest method whenUseHealthCheck_thenHealthChecked.
@Test
public void whenUseHealthCheck_thenHealthChecked() {
HealthCheckRegistry healthCheckRegistry = new HealthCheckRegistry();
healthCheckRegistry.register("db", new DatabaseHealthCheck());
healthCheckRegistry.register("uc", new UserCenterHealthCheck());
assertThat(healthCheckRegistry.getNames().size(), equalTo(2));
Map<String, HealthCheck.Result> results = healthCheckRegistry.runHealthChecks();
assertFalse(results.isEmpty());
results.forEach((k, v) -> assertTrue(v.isHealthy()));
healthCheckRegistry.unregister("uc");
assertThat(healthCheckRegistry.getNames().size(), equalTo(1));
}
Aggregations