Library Spring

Health


Health Manager

The HealthManager is responsible for gathering and managing the health data of the system, including information about the system's uptime, memory usage, processor status, and platform details. It continuously monitors the system’s health and provides this data when requested.

The HealthManager can be configured using specific properties defined in your application's configuration file (such as application.properties, application.yml or environment varaibles). These properties modify the behavior of the health manager and affect the health check response. Here are the key properties:

Application Name

application.name

Defines the name of the application or system. This value is used to generate the build information in the health check response. If not provided, it defaults to an empty string.

Application Version

application.version

Specifies the version of the application or system. This value is included in the build information in the health check response. If not specified, it defaults to an empty string.

Memory Threshold for Health Check

application.health.threshold.memory

Defines the memory usage threshold (in percentage). If the system's memory usage exceeds this threshold, the health check response will indicate a "low memory" state. The default value is 90, meaning the health check will trigger a low memory warning if memory usage exceeds 90%.

Add in your application

To integrate the health management functionality into your application, you can import the HealthManager class directly or use component scanning to automatically detect and register all classes in the net.dashio.spring.health package.

Import with class

@Import({HealthController.class, HealthManager.class})

Import with package

@ComponentScan("net.dashio.spring.health")

REST-GET/health

Health Controller

The HealthController is a Spring MVC controller that exposes an endpoint (typically /health) for external services to query the system’s health status. It uses the HealthManager to retrieve the current health information and returns this data in a standardized format (usually as a JSON response) with an HTTP 200 OK status if the system is healthy. This allows for easy monitoring of the system's operational state, often used in health checks for application uptime and performance monitoring tools.

Value Description

  • Name
    status
    Type
    integer
    Description

    HTTP status code representing the health check response.

  • Name
    startTime
    Type
    long
    Description

    Timestamp when the system started, in milliseconds since epoch.

  • Name
    currentTime
    Type
    long
    Description

    Current system time in milliseconds since epoch.

  • Name
    uptime
    Type
    long
    Description

    Duration the system has been up, in milliseconds.

  • Name
    threshold.memory
    Type
    double
    Description

    Configured memory usage threshold percentage.

  • Name
    threshold.lowMemory
    Type
    boolean
    Description

    Indicates if current memory usage exceeds the configured threshold.

  • Name
    build.name
    Type
    string
    Description

    Application or system name (empty by default).

  • Name
    build.version
    Type
    string
    Description

    Application or system version (empty by default).

  • Name
    platform.platform
    Type
    string
    Description

    Operating system name.

  • Name
    platform.platformVersion
    Type
    string
    Description

    Operating system version.

  • Name
    platform.platformArchitecture
    Type
    string
    Description

    System architecture, e.g., "amd64."

  • Name
    platform.javaVersion
    Type
    string
    Description

    Java runtime version.

  • Name
    processor.name
    Type
    string
    Description

    Processor name and model.

  • Name
    processor.count
    Type
    integer
    Description

    Number of physical processor cores.

  • Name
    processor.logicalCount
    Type
    integer
    Description

    Number of logical processors (threads).

  • Name
    processor.clock
    Type
    long
    Description

    Processor clock speed in MHz.

  • Name
    processor.averageLoad
    Type
    array
    Description

    Array representing the system load average over 1, 5, and 15 minutes.

  • Name
    memory.total
    Type
    long
    Description

    Total system memory in MB.

  • Name
    memory.available
    Type
    long
    Description

    Available system memory in MB.

  • Name
    memory.used
    Type
    long
    Description

    Used system memory in MB.

  • Name
    memory.memoryUsage
    Type
    double
    Description

    Percentage of memory usage.

  • Name
    memory.swap.total
    Type
    long
    Description

    Total swap memory in MB.

  • Name
    memory.swap.available
    Type
    long
    Description

    Available swap memory in MB.

  • Name
    memory.swap.used
    Type
    long
    Description

    Used swap memory in MB.

  • Name
    memory.swap.memoryUsage
    Type
    double
    Description

    Percentage of swap memory usage.

Health Response

{
    "status": 200,
    "startTime": 1731522165615,
    "currentTime": 1731525559457,
    "uptime": 3393842,
    "threshold": {
        "memory": 90.0,
        "lowMemory": false
    },
    "build": {
        "name": "",
        "version": ""
    },
    "platform": {
        "platform": "Windows 10",
        "platformVersion": "10.0",
        "platformArchitecture": "amd64",
        "javaVersion": "21.0.3"
    },
    "processor": {
        "name": "Intel(R) Core(TM) i5-9300H CPU @ 2.40GHz",
        "count": 4,
        "logicalCount": 8,
        "clock": 2400,
        "averageLoad": [-1.0, -1.0, -1.0]
    },
    "memory": {
        "total": 32616,
        "available": 16554,
        "used": 16062,
        "memoryUsage": 49.246031950390886,
        "swap": {
            "total": 9216,
            "available": 8940,
            "used": 275,
            "memoryUsage": 2.984195285373264
        }
    }
}

Was this page helpful?