UNPKG

@mdf.js/service-registry

Version:

MMS - API - Service Registry

114 lines 5.32 kB
/** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ import { Health, Layer } from '@mdf.js/core'; import { LoggerInstance } from '@mdf.js/logger'; import EventEmitter from 'events'; /** * 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. */ export declare class Aggregator extends EventEmitter { private readonly metadata; private readonly logger; /** Components monitored by the aggregator */ private readonly components; /** External checks, included in the aggregator to be exposed in the overall diagnostic */ private readonly externalChecks; /** Worker checks, included in the aggregator to be exposed in the overall diagnostic */ private readonly workerChecks; /** Base Health Status*/ protected readonly baseHealth: Omit<Layer.App.Health, 'status' | 'checks'>; /** Array of notes to be included in the health status */ private readonly notes; /** Public output */ output: string | undefined; /** * Create an instance of the Health aggregator * @param metadata - Metadata describing the application, used to enrich the health data. * @param logger - Logger instance for logging activities related to health monitoring. */ constructor(metadata: Layer.App.Metadata, logger: LoggerInstance); /** * Computes the health status of the application by aggregating individual component checks * and determining the overall status. */ get health(): Layer.App.Health; /** * Aggregates checks from all sources: registered components, external checks, and worker checks. */ get checks(): Health.Checks; /** Overall component status */ get status(): Health.Status; /** * Register a resource or a list of resources to monitor for errors. * @param component - Resource or list of resources to be registered */ register(component: Layer.App.Resource | Layer.App.Resource[]): void; /** * Adds a timestamped note to the health status. * @param note - Note to be added. */ addNote(note: string): void; /** * 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. * @param component - component identification * @param measure - measure identification * @param check - check to be updated or included * @returns true, if the check has been updated or included */ addExternalCheck(component: string, measure: string, check: Health.Check): boolean; /** * Update the health checks associated with workers. * @param checks - Checks to be updated or included */ updateWorkersChecks(checks: Health.Checks): 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. * @param component - component identification * @param measure - measure identification * @param check - check to be updated or included * @returns true, if the check has been updated or included */ addWorkerCheck(component: string, measure: string, check: Health.Check): boolean; /** Event handler for status event */ private readonly statusEventHandler; /** * Check if the check is valid to be included in the health status * @param check - Check to be validated * @returns */ private isValidCheck; /** Check if the resource is valid to be monitored */ private isValidResource; /** Return the the uptime of service as a check */ private get uptime(); /** Close the aggregator */ close(): void; } //# sourceMappingURL=Aggregator.d.ts.map