@Contract public abstract class BaseHealthCheck<O extends HealthCheckExecutionOptions,C extends Checker> extends Object implements HealthCheckConstants
| Modifier and Type | Field and Description |
|---|---|
protected Class<C> |
checkerType |
protected HealthCheckService |
healthCheckService |
protected O |
options |
DEFAULT_CONNECTION_POOL_NAME, DEFAULT_CPU_USAGE_NAME, DEFAULT_ENABLED, DEFAULT_GARBAGE_COLLECTOR_NAME, DEFAULT_HEAP_MEMORY_USAGE_NAME, DEFAULT_HOGGING_THREADS_NAME, DEFAULT_MACHINE_MEMORY_USAGE_NAME, DEFAULT_MICROPROFILE_HEALTHCHECK_NAME, DEFAULT_RETRY_COUNT, DEFAULT_STUCK_THREAD_NAME, DEFAULT_THRESHOLD_PERCENTAGE, DEFAULT_TIME, DEFAULT_TIMEOUT, DEFAULT_UNIT, FIVE_MIN, OLD_CONCURRENTMARKSWEEP, OLD_G1GC, OLD_MARK_SWEEP_COMPACT, OLD_PS_MARKSWEEP, ONE_GB, ONE_KB, ONE_MB, ONE_MIN, ONE_SEC, THRESHOLD_CRITICAL, THRESHOLD_DEFAULTVAL_CRITICAL, THRESHOLD_DEFAULTVAL_GOOD, THRESHOLD_DEFAULTVAL_WARNING, THRESHOLD_GOOD, THRESHOLD_WARNING, YOUNG_COPY, YOUNG_G1GC, YOUNG_PARNEW, YOUNG_PS_SCAVENGE| Constructor and Description |
|---|
BaseHealthCheck() |
| Modifier and Type | Method and Description |
|---|---|
protected TimeUnit |
asTimeUnit(String unit)
Converts a string representing a timeunit to the value
i.e.
|
protected HealthCheckExecutionOptions |
constructBaseOptions(Checker checker) |
abstract O |
constructOptions(C c) |
protected HealthCheckResultStatus |
decideOnStatusWithDuration(long duration)
Determines the level of of the healthcheck based on a time
|
HealthCheckResult |
doCheck() |
protected abstract HealthCheckResult |
doCheckInternal() |
Class<C> |
getCheckerType() |
int |
getChecksDone() |
int |
getChecksFailed() |
protected abstract String |
getDescription()
The key for a human-friendly description of the healthcheck
|
O |
getOptions() |
boolean |
isInProgress() |
boolean |
isReady() |
protected <T extends BaseHealthCheck> |
postConstruct(T t,
Class<C> checkerType) |
protected String |
prettyPrintBytes(long value)
Returns the amount in a human-friendly string
|
protected String |
prettyPrintStackTrace(StackTraceElement[] elements)
Returns a string of tab-separated stack trace elements
|
String |
resolveDescription()
Returns a human-friendly description of the healthcheck
|
void |
sendNotification(String name,
HealthCheckResult checkResult,
Level level)
Sends a notification to all notifier enabled with the healthcheck service.
|
void |
setOptions(O options) |
@Inject protected HealthCheckService healthCheckService
protected O extends HealthCheckExecutionOptions options
public final HealthCheckResult doCheck()
protected abstract HealthCheckResult doCheckInternal()
public boolean isInProgress()
public int getChecksDone()
public int getChecksFailed()
public boolean isReady()
protected <T extends BaseHealthCheck> O postConstruct(T t, Class<C> checkerType)
protected HealthCheckExecutionOptions constructBaseOptions(Checker checker)
protected TimeUnit asTimeUnit(String unit)
"MILLISECONDS" to TimeUnit.MILLISECONDSunit - protected HealthCheckResultStatus decideOnStatusWithDuration(long duration)
duration - length of time taken in millisecondsHealthCheckResultStatus.CRITICAL if duration > 5 minutes;
HealthCheckResultStatus.WARNING if duration > 1 minute;
HealthCheckResultStatus.GOOD if duration > 0;
otherwise HealthCheckResultStatus.CHECK_ERRORprotected String prettyPrintBytes(long value)
i.e. with an input of 1024 the result will be "1 Kb"; for an input of 20000000 the result would be "19 Mb"
Result is always rounded down number of the largest unit of which there is at least one of that unit.
Unit can be Gb, Mb, Kb or bytes.
value - protected String prettyPrintStackTrace(StackTraceElement[] elements)
elements - public String resolveDescription()
protected abstract String getDescription()
public O getOptions()
public void setOptions(O options)
public void sendNotification(String name, HealthCheckResult checkResult, Level level)
checkResult - information collected by the regarding health check servicelevel - Level of the message to sendname - Name of the checker executedCopyright © 2019. All rights reserved.