The Aggregator class serves as a central point for collecting and aggregating health checks and statuses from various components within an application. It also allows for the integration of external and worker-specific checks to provide a comprehensive view of the application's health status.

This class extends EventEmitter to emit status updates, enabling other parts of the application to react to changes in health status as necessary.

Hierarchy

  • EventEmitter
    • Aggregator

Constructors

  • Create an instance of the Health aggregator

    Parameters

    • metadata: Metadata

      Metadata describing the application, used to enrich the health data.

    • logger: LoggerInstance

      Logger instance for logging activities related to health monitoring.

    Returns Aggregator

Properties

output: undefined | string = undefined

Public output

Accessors

  • get checks(): Checks<any>
  • Aggregates checks from all sources: registered components, external checks, and worker checks.

    Returns Checks<any>

  • get health(): Layer.App.Health
  • Computes the health status of the application by aggregating individual component checks and determining the overall status.

    Returns Layer.App.Health

  • get status(): "pass" | "fail" | "warn"
  • Overall component status

    Returns "pass" | "fail" | "warn"

Methods

  • Update or add a check measure. This should be used to inform about the state of resources behind the Component/Microservice, for example states of connections with field devices.

    The new check will be taking into account in the overall health status. The new check will be included in the checks object with the key "component:measure". If this key already exists, the componentId of the check parameter will be checked, if there is a check with the same componentId in the array, the check will be updated, in other case the new check will be added to the existing array.

    The maximum number external checks entries is 10, and the maximum number of checks per entry is 100.

    Parameters

    • component: string

      component identification

    • measure: string

      measure identification

    • check: Check<any>

      check to be updated or included

    Returns boolean

    true, if the check has been updated or included

  • Adds a timestamped note to the health status.

    Parameters

    • note: string

      Note to be added.

    Returns void

  • Update or add a check measure for a worker. This should be used to inform about the state of resources behind the worker. The new check will be taking into account in the overall health status. The new check will be included in the checks object with the key "component:measure". If this key already exists, the componentId of the check parameter will be checked, if there is a check with the same componentId in the array, the check will be updated, in other case the new check will be added to the existing array.

    Parameters

    • component: string

      component identification

    • measure: string

      measure identification

    • check: Check<any>

      check to be updated or included

    Returns boolean

    true, if the check has been updated or included

  • Close the aggregator

    Returns void

  • Register a resource or a list of resources to monitor for errors.

    Parameters

    Returns void

  • Update the health checks associated with workers.

    Parameters

    • checks: Checks<any>

      Checks to be updated or included

    Returns void