Class ResourceHealthIndicator

java.lang.Object
com.tnsai.quality.observability.health.ResourceHealthIndicator
All Implemented Interfaces:
HealthIndicator

public class ResourceHealthIndicator extends Object implements 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:
  • 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 status
      cpuThreshold - CPU load threshold (0.0-1.0) for degraded status
  • Method Details

    • getName

      public String getName()
      Description copied from interface: HealthIndicator
      Gets the name of this health indicator.

      Default implementation returns the simple class name.

      Specified by:
      getName in interface HealthIndicator
      Returns:
      the indicator name
    • check

      public HealthCheckResult check()
      Description copied from interface: HealthIndicator
      Performs 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:
      check in interface HealthIndicator
      Returns:
      the health check result
    • getTimeout

      public Duration getTimeout()
      Description copied from interface: HealthIndicator
      Gets the timeout for this health check.
      Specified by:
      getTimeout in interface HealthIndicator
      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