public interface HealthCheck
Health checks are typically used for reporting and monitoring purposes.
The results exposed by health checks can be reported via HTTP by a HealthCheckHandler
.
The actual check is implemented by the check(Registry)
method, that returns a promise for a HealthCheck.Result
.
The inspiration for health checks in Ratpack comes from the Dropwizard Metrics library. Ratpack health checks are different in that they support non blocking checks, and all health checks require a unique name.
HealthCheckHandler
Modifier and Type | Interface and Description |
---|---|
static class |
HealthCheck.Result
The result of a health check.
|
Modifier and Type | Method and Description |
---|---|
Promise<HealthCheck.Result> |
check(Registry registry)
Checks the health of the component, providing a promise for the result.
|
static Promise<HealthCheckResults> |
checkAll(Registry registry,
Iterable<? extends HealthCheck> healthChecks)
Execute health checks.
|
static Promise<HealthCheckResults> |
checkAll(Registry registry,
Throttle throttle,
Iterable<? extends HealthCheck> healthChecks)
Execute health checks.
|
String |
getName()
The unique name of the health check.
|
static HealthCheck |
of(String name,
Function<? super Registry,? extends Promise<HealthCheck.Result>> func)
Convenience factory for health check implementations.
|
String getName()
Each health check within an application must have a unique name.
Promise<HealthCheck.Result> check(Registry registry) throws Exception
This method returns a promise to allow check implementations to be asynchronous.
If the implementation does not need to be asynchronous, the result can be returned via Promise.value(Object)
.
The registry
argument is the server registry, from which other supporting objects can be obtained.
If this method throws an exception, it is logically equivalent to returned an unhealthy result with the thrown exception.
If the method returns a failed promise, it will be converted to a result using HealthCheck.Result.unhealthy(Throwable)
.
registry
- the server registryException
- anystatic HealthCheck of(String name, Function<? super Registry,? extends Promise<HealthCheck.Result>> func)
import ratpack.test.exec.ExecHarness;
import ratpack.exec.Promise;
import ratpack.registry.Registry;
import ratpack.health.HealthCheck;
import static org.junit.Assert.*;
public class Example {
public static void main(String... args) throws Exception {
HealthCheck.Result result = ExecHarness.yieldSingle(e ->
HealthCheck.of("test", registry ->
Promise.value(HealthCheck.Result.healthy())
).check(Registry.empty())
).getValue();
assertTrue(result.isHealthy());
}
}
name
- a name of health checkfunc
- a health check implementationstatic Promise<HealthCheckResults> checkAll(Registry registry, Iterable<? extends HealthCheck> healthChecks)
The checks will be executed in parallel.
registry
- the registry to pass to each health checkhealthChecks
- the health checks to executestatic Promise<HealthCheckResults> checkAll(Registry registry, Throttle throttle, Iterable<? extends HealthCheck> healthChecks)
The checks will be executed in parallel.
registry
- the registry to pass to each health checkthrottle
- the throttle to use to constrain the parallelism of the checkshealthChecks
- the health checks to execute