public class CodaHaleHealthCheckModule extends AbstractModule
Health checks verify that application components or responsibilities are performing as expected.
To use this module one has to register the module and create health checks by simply creating a class that extends NamedHealthCheck and bind it with Guice.
This will automatically add it to the application wide HealthCheckRegistry.
Health checks can be run by obtaining the HealthCheckRegistry via dependency injection or context registry lookup,
then calling HealthCheckRegistry.runHealthChecks().
To expose the health check status over HTTP, see HealthCheckHandler.
Example health checks: (Groovy DSL)
import com.codahale.metrics.health.HealthCheck
import com.codahale.metrics.health.HealthCheckRegistry
import ratpack.codahale.healthcheck.CodaHaleHealthCheckModule
import ratpack.codahale.healthcheck.HealthCheckHandler
import ratpack.codahale.healthcheck.NamedHealthCheck
import static ratpack.groovy.Groovy.ratpack
class FooHealthCheck extends NamedHealthCheck {
protected HealthCheck.Result check() throws Exception {
// perform the health check logic here and return HealthCheck.Result.healthy() or HealthCheck.Result.unhealthy("Unhealthy message")
HealthCheck.Result.healthy()
}
def String getName() {
"foo_health_check"
}
}
ratpack {
bindings {
add new CodaHaleHealthCheckModule()
bind FooHealthCheck // if you don't bind the health check with Guice it will not be automatically registered
}
handlers {
// Using the provided handler…
get("health-check/:name", new HealthCheckHandler())
// Using a custom handler to run all health checks…
get("healthChecks-custom") { HealthCheckRegistry healthCheckRegistry ->
render healthCheckRegistry.runHealthChecks().toString()
}
}
}
| Constructor and Description |
|---|
CodaHaleHealthCheckModule() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
configure() |
addError, addError, addError, bind, bind, bind, bindConstant, binder, bindInterceptor, bindListener, bindListener, bindScope, configure, convertToTypes, currentStage, getMembersInjector, getMembersInjector, getProvider, getProvider, install, requestInjection, requestStaticInjection, requireBinding, requireBindingprotected void configure()
configure in class AbstractModule