proactive-deps
Version:
A library for managing proactive dependency checks in Node.js applications.
52 lines • 2.28 kB
TypeScript
import promClient from 'prom-client';
import { DependencyMonitorInterface, DependencyMonitorOptions, DependencyCheckOptions, DependencyStatus } from './types';
/**
* DependencyMonitor is a class that monitors the status of various dependencies
* (e.g., databases, APIs) and provides methods to check their health and latency.
* It uses a cache to store the results of the checks and can be configured
* to refresh the cache at specified intervals.
* It also provides a method to get Prometheus metrics for the monitored dependencies.
* @class DependencyMonitor
*/
declare class DependencyMonitor implements DependencyMonitorInterface {
private _dependencies;
private _cache;
private _dependencyCheckInterval;
private _refreshThresholdMs;
private _cacheDurationMs;
private _checkIntervalMs;
private _registry?;
private _latencyGauge?;
private _healthGauge?;
private _metricsInitialized;
private _collectDefaultMetrics;
checkIntervalStarted: boolean;
/**
* Creates an instance of DependencyMonitor.
* @param {DependencyMonitorOptions} [options] - Optional configuration options for the monitor.
* @default { cacheDurationMs: 60000, refreshThresholdMs: 5000, checkIntervalMs: 15000 }
* @example
* const monitor = new DependencyMonitor({
* cacheDurationMs: 60000, // Cache duration of 1 minute
* refreshThresholdMs: 5000, // Refresh threshold of 5 seconds
* checkIntervalMs: 15000, // Check interval of 15 seconds
* });
*/
constructor(options?: DependencyMonitorOptions);
startDependencyCheckInterval(): void;
stopDependencyCheckInterval(): void;
register(dependency: DependencyCheckOptions): void;
private _getDependencyStatus;
private _getAllDependenciesStatus;
getStatus(dependencyName: string): Promise<DependencyStatus>;
getAllStatuses(): Promise<DependencyStatus[]>;
getPrometheusMetrics(): Promise<string>;
/**
* Returns the underlying prom-client Registry if initialized.
*/
getPrometheusRegistry(): promClient.Registry<"text/plain; version=0.0.4; charset=utf-8"> | undefined;
private _initPromClient;
private _updateMetrics;
}
export { DependencyMonitor };
//# sourceMappingURL=monitor.d.ts.map