@mdf.js/service-registry
Version:
MMS - API - Service Registry
92 lines • 4.41 kB
TypeScript
/**
* 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 { Crash, Links, Multi } from '@mdf.js/crash';
import { ErrorRecord, Metrics } from './registries';
import { ObservabilityOptions } from './types';
/**
* Represents a comprehensive observability service that aggregates various registries
* including health checks, metrics, and error logging. This class is responsible for
* managing and initializing these registries, attaching services to them, and integrating
* them into a unified observability application.
*
* The service leverages an `ObservabilityAppManager` to orchestrate the express application
* that serves observability endpoints. It allows for dynamic registration of services
* to enable monitoring, health checks, and error tracking.
*/
export declare class Observability {
readonly options: ObservabilityOptions;
/** Manages the Express application dedicated to observability features. */
private readonly _app;
/** Collection of registries (Health, Metrics, Errors) utilized by observability. */
private readonly _registers;
/** Central registry for capturing and reporting errors across services. */
private readonly _errorsRegistry;
/** Central registry for collecting and exposing metrics from services. */
private readonly _metricsRegistry;
/** Central registry for collecting and exposing metrics from services. */
private readonly _healthRegistry;
/**
* Initializes the observability service with specified options, setting up
* health, metrics, and error registries based on those options.
* @param options - Configuration options for observability, including settings
* for health checks, metrics collection, and error logging.
*/
constructor(options: ObservabilityOptions);
/**
* Attaches a new service to be monitored under the observability framework.
* Services are components of your application that you wish to monitor for
* health, track errors for, and collect metrics on.
* @param observable - The service to attach to observability.
*/
attach(observable: Layer.Observable): void;
/** Start the observability service */
start(): Promise<void>;
/** Stop the observability service */
stop(): Promise<void>;
/** Close the observability service */
close(): Promise<void>;
/**
* Adds an error to the registry, converting it to a structured format.
* @param error - The error to register.
*/
push(error: Crash | Multi | Error): 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 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
*/
addCheck(component: string, measure: string, check: Health.Check): boolean;
/** @returns The health of the monitored application */
get health(): Layer.App.Health;
/** @returns The status of the monitored application */
get status(): Health.Status;
/** @returns The metrics of the monitored application */
get metrics(): Promise<Metrics.Response>;
/** @returns The errors of the monitored application */
get errors(): ErrorRecord[];
/** @returns The observability rest api access end points */
get links(): Links;
}
//# sourceMappingURL=Observability.d.ts.map