use of com.codahale.metrics.health.HealthCheck in project metrics by dropwizard.
the class HealthCheckServletTest method returnsA200IfAllHealthChecksAreHealthy.
@Test
public void returnsA200IfAllHealthChecksAreHealthy() throws Exception {
registry.register("fun", new HealthCheck() {
@Override
protected Result check() throws Exception {
return Result.healthy("whee");
}
});
processRequest();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContent()).isEqualTo("{\"fun\":{\"healthy\":true,\"message\":\"whee\"}}");
assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
}
use of com.codahale.metrics.health.HealthCheck in project metrics by dropwizard.
the class ThreadDeadlockHealthCheckTest method isUnhealthyIfThreadsAreDeadlocked.
@Test
public void isUnhealthyIfThreadsAreDeadlocked() throws Exception {
final Set<String> threads = new TreeSet<String>();
threads.add("one");
threads.add("two");
final ThreadDeadlockDetector detector = mock(ThreadDeadlockDetector.class);
final ThreadDeadlockHealthCheck healthCheck = new ThreadDeadlockHealthCheck(detector);
when(detector.getDeadlockedThreads()).thenReturn(threads);
final HealthCheck.Result result = healthCheck.execute();
assertThat(result.isHealthy()).isFalse();
assertThat(result.getMessage()).isEqualTo("[one, two]");
}
use of com.codahale.metrics.health.HealthCheck in project jstorm by alibaba.
the class NettyClient method registerMetrics.
public void registerMetrics() {
if (this.enableNettyMetrics) {
sendTimer = (AsmHistogram) JStormMetrics.registerNettyMetric(MetricUtils.nettyMetricName(AsmMetric.mkName(MetricDef.NETTY_CLI_SEND_TIME, nettyConnection), MetricType.HISTOGRAM), new AsmHistogram());
sendSpeed = (AsmMeter) JStormMetrics.registerNettyMetric(MetricUtils.nettyMetricName(AsmMetric.mkName(MetricDef.NETTY_CLI_SEND_SPEED, nettyConnection), MetricType.METER), new AsmMeter());
CacheGaugeHealthCheck cacheGauge = new CacheGaugeHealthCheck(messageBuffer, MetricDef.NETTY_CLI_CACHE_SIZE + ":" + nettyConnection.toString());
JStormMetrics.registerNettyMetric(MetricUtils.nettyMetricName(AsmMetric.mkName(MetricDef.NETTY_CLI_CACHE_SIZE, nettyConnection), MetricType.GAUGE), new AsmGauge(cacheGauge));
JStormMetrics.registerNettyMetric(MetricUtils.nettyMetricName(AsmMetric.mkName(MetricDef.NETTY_CLI_SEND_PENDING, nettyConnection), MetricType.GAUGE), new AsmGauge(new com.codahale.metrics.Gauge<Double>() {
@Override
public Double getValue() {
return ((Long) pendings.get()).doubleValue();
}
}));
JStormHealthCheck.registerWorkerHealthCheck(MetricDef.NETTY_CLI_CACHE_SIZE + ":" + nettyConnection.toString(), cacheGauge);
}
JStormHealthCheck.registerWorkerHealthCheck(MetricDef.NETTY_CLI_CONNECTION + ":" + nettyConnection.toString(), new HealthCheck() {
HealthCheck.Result healthy = HealthCheck.Result.healthy();
HealthCheck.Result unhealthy = HealthCheck.Result.unhealthy("NettyConnection " + nettyConnection.toString() + " is broken.");
@Override
protected Result check() throws Exception {
if (isChannelReady() == null) {
return unhealthy;
} else {
return healthy;
}
}
});
}
use of com.codahale.metrics.health.HealthCheck in project metrics by dropwizard.
the class HealthCheckServletTest method returnsA500IfAnyHealthChecksAreUnhealthy.
@Test
public void returnsA500IfAnyHealthChecksAreUnhealthy() throws Exception {
registry.register("fun", new HealthCheck() {
@Override
protected Result check() throws Exception {
return Result.healthy("whee");
}
});
registry.register("notFun", new HealthCheck() {
@Override
protected Result check() throws Exception {
return Result.unhealthy("whee");
}
});
processRequest();
assertThat(response.getStatus()).isEqualTo(500);
assertThat(response.getContent()).isEqualTo("{\"fun\":{\"healthy\":true,\"message\":\"whee\"},\"notFun\":{\"healthy\":false,\"message\":\"whee\"}}");
assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
}
use of com.codahale.metrics.health.HealthCheck in project metrics by dropwizard.
the class HealthCheckServletTest method optionallyPrettyPrintsTheJson.
@Test
public void optionallyPrettyPrintsTheJson() throws Exception {
registry.register("fun", new HealthCheck() {
@Override
protected Result check() throws Exception {
return Result.healthy("whee");
}
});
request.setURI("/healthchecks?pretty=true");
processRequest();
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getContent()).isEqualTo(String.format("{%n" + " \"fun\" : {%n" + " \"healthy\" : true,%n" + " \"message\" : \"whee\"%n" + " }%n" + "}"));
assertThat(response.get(HttpHeader.CONTENT_TYPE)).isEqualTo("application/json");
}
Aggregations