@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_RETRY_COUNT, DEFAULT_THRESHOLD_PERCENTAGE, DEFAULT_TIME, DEFAULT_UNIT, DEFUALT_STUCK_THEAD_NAME, 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
|
abstract HealthCheckResult |
doCheck() |
Class<C> |
getCheckerType() |
protected abstract String |
getDescription()
The key for a human-friendly description of the healthcheck
|
O |
getOptions() |
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(Level level,
String message,
Object[] parameters)
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 abstract HealthCheckResult doCheck()
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(Level level, String message, Object[] parameters)
The subject of the notification will be: "Health Check notification with severity level: ${level}
level - Level of the message to sendmessage - A simple message to sendparameters - An array of extra information to sendCopyright © 2017. All rights reserved.