Class ResourceHealthIndicator
java.lang.Object
com.tnsai.quality.observability.health.ResourceHealthIndicator
- All Implemented Interfaces:
HealthIndicator
Health indicator for system resources.
Monitors:
- Heap memory usage
- CPU load
- Thread count
- Available processors
Example usage:
HealthRegistry.getInstance()
.register(new ResourceHealthIndicator());
// With custom thresholds
HealthRegistry.getInstance()
.register(new ResourceHealthIndicator(0.9, 0.9)); // 90% thresholds
- See Also:
-
Field Summary
Fields inherited from interface com.tnsai.quality.observability.health.HealthIndicator
DEFAULT_TIMEOUT -
Constructor Summary
ConstructorsConstructorDescriptionCreates a resource health indicator with default thresholds.ResourceHealthIndicator(double memoryThreshold, double cpuThreshold) Creates a resource health indicator with custom thresholds. -
Method Summary
Modifier and TypeMethodDescriptioncheck()Performs the health check and returns the result.doubleGets current heap memory usage as a percentage.getName()Gets the name of this health indicator.intGets current thread count.Gets the timeout for this health check.booleanChecks if there are any deadlocked threads.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.tnsai.quality.observability.health.HealthIndicator
checkAsync, checkWithTimeout
-
Constructor Details
-
ResourceHealthIndicator
public ResourceHealthIndicator()Creates a resource health indicator with default thresholds. -
ResourceHealthIndicator
public ResourceHealthIndicator(double memoryThreshold, double cpuThreshold) Creates a resource health indicator with custom thresholds.- Parameters:
memoryThreshold- memory usage threshold (0.0-1.0) for degraded statuscpuThreshold- CPU load threshold (0.0-1.0) for degraded status
-
-
Method Details
-
getName
Description copied from interface:HealthIndicatorGets the name of this health indicator.Default implementation returns the simple class name.
- Specified by:
getNamein interfaceHealthIndicator- Returns:
- the indicator name
-
check
Description copied from interface:HealthIndicatorPerforms the health check and returns the result.Implementations should:
- Return quickly (under 10 seconds)
- Not throw exceptions (return DOWN status instead)
- Include relevant details in the result
- Specified by:
checkin interfaceHealthIndicator- Returns:
- the health check result
-
getTimeout
Description copied from interface:HealthIndicatorGets the timeout for this health check.- Specified by:
getTimeoutin interfaceHealthIndicator- Returns:
- the timeout duration
-
getHeapUsageRatio
public double getHeapUsageRatio()Gets current heap memory usage as a percentage.- Returns:
- memory usage (0.0-1.0)
-
getThreadCount
public int getThreadCount()Gets current thread count.- Returns:
- thread count
-
hasDeadlock
public boolean hasDeadlock()Checks if there are any deadlocked threads.- Returns:
- true if deadlock detected
-