Class BaseHealthCheck<O extends HealthCheckExecutionOptions,C extends Checker>
- java.lang.Object
-
- fish.payara.nucleus.healthcheck.preliminary.BaseHealthCheck<O,C>
-
- All Implemented Interfaces:
HealthCheckConstants
- Direct Known Subclasses:
BaseThresholdHealthCheck
,HoggingThreadsHealthCheck
,MicroProfileHealthChecker
,MicroProfileMetricsCheck
,StuckThreadsHealthCheck
@Contract public abstract class BaseHealthCheck<O extends HealthCheckExecutionOptions,C extends Checker> extends Object implements HealthCheckConstants
Base class for all health check services- Since:
- 4.1.1.161
- Author:
- mertcaliskan
-
-
Field Summary
Fields Modifier and Type Field Description protected Class<C>
checkerType
protected HealthCheckService
healthCheckService
protected O
options
-
Fields inherited from interface fish.payara.nucleus.healthcheck.HealthCheckConstants
DEFAULT_ADD_TO_MICROPROFILE_HEALTH, 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_MICROPROFILE_METRICS_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 Summary
Constructors Constructor Description BaseHealthCheck()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 timeHealthCheckResult
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 healthcheckHealthCheckResultStatus
getMostRecentCumulativeStatus()
HealthCheckResult
getMostRecentResult()
O
getOptions()
boolean
isEnabled()
boolean
isInProgress()
boolean
isReady()
protected <T extends BaseHealthCheck>
OpostConstruct(T t, Class<C> checkerType)
protected String
prettyPrintBytes(long value)
Returns the amount in a human-friendly stringprotected String
prettyPrintStackTrace(StackTraceElement[] elements)
Returns a string of tab-separated stack trace elementsString
resolveDescription()
Returns a human-friendly description of the healthcheckvoid
sendNotification(String name, HealthCheckResult checkResult, Level level)
Sends a notification to all notifier enabled with the healthcheck service.void
setOptions(O options)
-
-
-
Field Detail
-
healthCheckService
@Inject protected HealthCheckService healthCheckService
-
options
protected O extends HealthCheckExecutionOptions options
-
-
Method Detail
-
doCheck
public final HealthCheckResult doCheck()
-
doCheckInternal
protected abstract HealthCheckResult doCheckInternal()
-
getMostRecentCumulativeStatus
public HealthCheckResultStatus getMostRecentCumulativeStatus()
-
getMostRecentResult
public HealthCheckResult getMostRecentResult()
-
isInProgress
public boolean isInProgress()
-
getChecksDone
public int getChecksDone()
-
getChecksFailed
public int getChecksFailed()
-
isReady
public boolean isReady()
-
isEnabled
public boolean isEnabled()
-
postConstruct
protected <T extends BaseHealthCheck> O postConstruct(T t, Class<C> checkerType)
-
constructBaseOptions
protected HealthCheckExecutionOptions constructBaseOptions(Checker checker)
-
asTimeUnit
protected TimeUnit asTimeUnit(String unit)
Converts a string representing a timeunit to the value i.e."MILLISECONDS"
toTimeUnit.MILLISECONDS
- Parameters:
unit
-- Returns:
-
decideOnStatusWithDuration
protected HealthCheckResultStatus decideOnStatusWithDuration(long duration)
Determines the level of of the healthcheck based on a time- Parameters:
duration
- length of time taken in milliseconds- Returns:
HealthCheckResultStatus.CRITICAL
if duration > 5 minutes;HealthCheckResultStatus.WARNING
if duration > 1 minute;HealthCheckResultStatus.GOOD
if duration > 0; otherwiseHealthCheckResultStatus.CHECK_ERROR
-
prettyPrintBytes
protected String prettyPrintBytes(long value)
Returns the amount in a human-friendly stringi.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.
- Parameters:
value
-- Returns:
-
prettyPrintStackTrace
protected String prettyPrintStackTrace(StackTraceElement[] elements)
Returns a string of tab-separated stack trace elements- Parameters:
elements
-- Returns:
-
resolveDescription
public String resolveDescription()
Returns a human-friendly description of the healthcheck- Returns:
- Since:
- 4.1.2.173
-
getDescription
protected abstract String getDescription()
The key for a human-friendly description of the healthcheck- Returns:
-
getOptions
public O getOptions()
-
setOptions
public void setOptions(O options)
-
sendNotification
public void sendNotification(String name, HealthCheckResult checkResult, Level level)
Sends a notification to all notifier enabled with the healthcheck service.- Parameters:
checkResult
- information collected by the regarding health check servicelevel
- Level of the message to sendname
- Name of the checker executed
-
-