/
HealthCheck.java
32 lines (28 loc) · 1.02 KB
/
HealthCheck.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.github.strengthened.prometheus.healthchecks;
/**
* A health check for a component of your application.
*/
public abstract class HealthCheck {
/**
* Perform a check of the application component.
*
* @return if the component is healthy, a healthy {@link HealthStatus}; otherwise, an unhealthy
* {@link HealthStatus} with a descriptive error message or exception
* @throws Exception if there is an unhandled error during the health check; this will result in a
* failed health check
*/
protected abstract HealthStatus check() throws Exception;
/**
* Executes the health check, catching and handling any exceptions raised by {@link #check()}.
*
* @return if the component is healthy, a healthy {@link HealthStatus}; otherwise, an unhealthy
* {@link HealthStatus} with a descriptive error message or exception
*/
public HealthStatus execute() {
try {
return check();
} catch (Exception ignored) {
return HealthStatus.UNHEALTHY;
}
}
}