Search in sources :

Example 1 with HealthCheck

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");
}
Also used : HealthCheck(com.codahale.metrics.health.HealthCheck) ServletException(javax.servlet.ServletException) Test(org.junit.Test)

Example 2 with HealthCheck

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]");
}
Also used : ThreadDeadlockDetector(com.codahale.metrics.jvm.ThreadDeadlockDetector) TreeSet(java.util.TreeSet) HealthCheck(com.codahale.metrics.health.HealthCheck) Test(org.junit.Test)

Example 3 with HealthCheck

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;
            }
        }
    });
}
Also used : AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge) AtomicLong(java.util.concurrent.atomic.AtomicLong) JStormHealthCheck(com.alibaba.jstorm.metric.JStormHealthCheck) HealthCheck(com.codahale.metrics.health.HealthCheck) AsmHistogram(com.alibaba.jstorm.common.metric.AsmHistogram) AsmMeter(com.alibaba.jstorm.common.metric.AsmMeter) QueueGauge(com.alibaba.jstorm.common.metric.QueueGauge) AsmGauge(com.alibaba.jstorm.common.metric.AsmGauge)

Example 4 with HealthCheck

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");
}
Also used : HealthCheck(com.codahale.metrics.health.HealthCheck) ServletException(javax.servlet.ServletException) Test(org.junit.Test)

Example 5 with HealthCheck

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");
}
Also used : HealthCheck(com.codahale.metrics.health.HealthCheck) ServletException(javax.servlet.ServletException) Test(org.junit.Test)

Aggregations

HealthCheck (com.codahale.metrics.health.HealthCheck)8 Test (org.junit.Test)4 ServletException (javax.servlet.ServletException)3 HealthCheckRegistry (com.codahale.metrics.health.HealthCheckRegistry)2 Bean (org.springframework.context.annotation.Bean)2 AsmGauge (com.alibaba.jstorm.common.metric.AsmGauge)1 AsmHistogram (com.alibaba.jstorm.common.metric.AsmHistogram)1 AsmMeter (com.alibaba.jstorm.common.metric.AsmMeter)1 QueueGauge (com.alibaba.jstorm.common.metric.QueueGauge)1 JStormHealthCheck (com.alibaba.jstorm.metric.JStormHealthCheck)1 ThreadDeadlockDetector (com.codahale.metrics.jvm.ThreadDeadlockDetector)1 HealthCheckCallback (com.netflix.appinfo.HealthCheckCallback)1 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)1 Entry (java.util.Map.Entry)1 TreeSet (java.util.TreeSet)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1