use of com.codahale.metrics.health.HealthCheckRegistry in project helios by spotify.
the class TotalHealthCheckGaugeTest method testAllFail.
@Test
public void testAllFail() {
final HealthCheckRegistry registry = new HealthCheckRegistry();
registry.register("fail1", stubHealthCheck(HealthCheck.Result.unhealthy("error")));
registry.register("fail2", stubHealthCheck(HealthCheck.Result.unhealthy("error")));
final TotalHealthCheckGauge gauge = new TotalHealthCheckGauge(registry);
assertThat(gauge.getValue(), is(0));
}
use of com.codahale.metrics.health.HealthCheckRegistry in project HikariCP by brettwooldridge.
the class TestMetrics method testSetters1.
@Test
public void testSetters1() throws Exception {
HikariDataSource ds = new HikariDataSource();
ds.setMaximumPoolSize(1);
ds.setDataSourceClassName("com.zaxxer.hikari.mocks.StubDataSource");
MetricRegistry metricRegistry = new MetricRegistry();
HealthCheckRegistry healthRegistry = new HealthCheckRegistry();
try {
Connection connection = ds.getConnection();
connection.close();
// After the pool as started, we can only set them once...
ds.setMetricRegistry(metricRegistry);
ds.setHealthCheckRegistry(healthRegistry);
// and never again...
ds.setMetricRegistry(metricRegistry);
Assert.fail("Should not have been allowed to set registry after pool started");
} catch (IllegalStateException ise) {
// pass
try {
ds.setHealthCheckRegistry(healthRegistry);
Assert.fail("Should not have been allowed to set registry after pool started");
} catch (IllegalStateException ise2) {
// pass
}
} finally {
ds.close();
}
}
use of com.codahale.metrics.health.HealthCheckRegistry in project HikariCP by brettwooldridge.
the class HikariConfig method setHealthCheckRegistry.
/**
* Set a Codahale HealthCheckRegistry to use for HikariCP.
*
* @param healthCheckRegistry the Codahale HealthCheckRegistry to set
*/
public void setHealthCheckRegistry(Object healthCheckRegistry) {
if (healthCheckRegistry != null) {
if (healthCheckRegistry instanceof String) {
try {
InitialContext initCtx = new InitialContext();
healthCheckRegistry = initCtx.lookup((String) healthCheckRegistry);
} catch (NamingException e) {
throw new IllegalArgumentException(e);
}
}
if (!(healthCheckRegistry instanceof HealthCheckRegistry)) {
throw new IllegalArgumentException("Class must be an instance of com.codahale.metrics.health.HealthCheckRegistry");
}
}
this.healthCheckRegistry = healthCheckRegistry;
}
use of com.codahale.metrics.health.HealthCheckRegistry in project metrics by dropwizard.
the class ExampleServer method main.
public static void main(String[] args) throws Exception {
COUNTER_1.inc();
COUNTER_2.inc();
final ThreadPool threadPool = new InstrumentedQueuedThreadPool(REGISTRY);
final Server server = new Server(threadPool);
final Connector connector = new ServerConnector(server, new InstrumentedConnectionFactory(new HttpConnectionFactory(), REGISTRY.timer("http.connection")));
server.addConnector(connector);
final ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/initial");
context.setAttribute(MetricsServlet.METRICS_REGISTRY, REGISTRY);
context.setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, new HealthCheckRegistry());
final ServletHolder holder = new ServletHolder(new AdminServlet());
context.addServlet(holder, "/dingo/*");
final InstrumentedHandler handler = new InstrumentedHandler(REGISTRY);
handler.setHandler(context);
server.setHandler(handler);
server.start();
server.join();
}
use of com.codahale.metrics.health.HealthCheckRegistry in project metrics by dropwizard.
the class HealthCheckServlet method init.
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
final ServletContext context = config.getServletContext();
if (null == registry) {
final Object registryAttr = context.getAttribute(HEALTH_CHECK_REGISTRY);
if (registryAttr instanceof HealthCheckRegistry) {
this.registry = (HealthCheckRegistry) registryAttr;
} else {
throw new ServletException("Couldn't find a HealthCheckRegistry instance.");
}
}
final Object executorAttr = context.getAttribute(HEALTH_CHECK_EXECUTOR);
if (executorAttr instanceof ExecutorService) {
this.executorService = (ExecutorService) executorAttr;
}
final Object filterAttr = context.getAttribute(HEALTH_CHECK_FILTER);
if (filterAttr instanceof HealthCheckFilter) {
filter = (HealthCheckFilter) filterAttr;
}
if (filter == null) {
filter = HealthCheckFilter.ALL;
}
this.mapper = new ObjectMapper().registerModule(new HealthCheckModule());
}
Aggregations