DropWizard没有注册我的健康检查

时间:2014-12-11 19:58:00

标签: java dropwizard health-monitoring codahale-metrics

在我的DropWizard( v0.7.0 )应用中,我有一个DummyHealthCheck,如下所示:

public class DummyHealthCheck extends HealthCheck {
    @Override
    protected Result check() throws Exception {
        return Result.healthy();
    }
}

然后在我的主Application impl:

public class MyApplication extends Application<MyConfiguration> {
    @Override
    public void run(MyConfiguration configuration, Environment environment)
            throws Exception {
        environment.jersey().register(new DummyHealthCheck());
    }
}

当我启动服务器时,它会成功启动(没有异常/错误),但是我收到以下消息:

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!    THIS APPLICATION HAS NO HEALTHCHECKS. THIS MEANS YOU WILL NEVER KNOW      !
!     IF IT DIES IN PRODUCTION, WHICH MEANS YOU WILL NEVER KNOW IF YOU'RE      !
!    LETTING YOUR USERS DOWN. YOU SHOULD ADD A HEALTHCHECK FOR EACH OF YOUR    !
!         APPLICATION'S DEPENDENCIES WHICH FULLY (BUT LIGHTLY) TESTS IT.       !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

但是当我去http://localhost:8081/healthcheck时,我看到了:

{"deadlocks":{"healthy":true}}
  1. 这里发生了什么?我如何注册健康检查?
  2. 另外,我已将DropWizard配置为在端口8443上使用SSL(自签名);我已经验证了这适用于我的正常端点。但是,我很惊讶地看到我的管理员应用仍在8081上通过HTTP公开。如何为HTTPS配置它?

1 个答案:

答案 0 :(得分:12)

问题1:

您不会在Jersey上注册,因为Health Checks是特定于DropWizard的。它们应注册如下

environment.healthChecks().register("dummy", new DummyHealthCheck());

解释here。如果 按上述方式注册,您会看到

{"deadlocks":{"healthy":true}, "dummy":{"healthy":true}}

问题2:

我认为你已经做过与

类似的事了
server:
  applicationConnectors:
    - type: https
      port: 8443
      keyStorePath: example.keystore
      keyStorePassword: example
      validateCerts: false

在您的yaml中,如here所示。这仅适用于应用程序。您还需要配置管理员

server:
  applicationConnectors:
  - ...
  adminConnectors:
  - type: https
    port: 8444    // should a different port from the application
    keyStorePath: example.keystore
    keyStorePassword: example
    validateCerts: false