Interface HealthCheck
-
- All Known Implementing Classes:
HikariHealthCheck
public interface HealthCheck
Reports on the health of some aspect of the system.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 aHealthCheck.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.
- See Also:
HealthCheckHandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
HealthCheck.Result
The result of a health check.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method 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.
-
-
-
Method Detail
-
getName
String getName()
The unique name of the health check.Each health check within an application must have a unique name.
- Returns:
- the name of the health check
-
check
Promise<HealthCheck.Result> check(Registry registry) throws Exception
Checks the health of the component, providing a promise for the result.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)
.- Parameters:
registry
- the server registry- Returns:
- a promise for the result
- Throws:
Exception
- any
-
of
static HealthCheck of(String name, Function<? super Registry,? extends Promise<HealthCheck.Result>> func)
Convenience factory for health check implementations.import ... 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()); } }
- Parameters:
name
- a name of health checkfunc
- a health check implementation- Returns:
- a named health check implementation
-
checkAll
static Promise<HealthCheckResults> checkAll(Registry registry, Iterable<? extends HealthCheck> healthChecks)
Execute health checks.The checks will be executed in parallel.
- Parameters:
registry
- the registry to pass to each health checkhealthChecks
- the health checks to execute- Returns:
- the results
- Since:
- 1.5
-
checkAll
static Promise<HealthCheckResults> checkAll(Registry registry, Throttle throttle, Iterable<? extends HealthCheck> healthChecks)
Execute health checks.The checks will be executed in parallel.
- Parameters:
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- Returns:
- the results
- Since:
- 1.5
-
-