proactive-deps
    Preparing search index...

    Interface DependencyMonitorInterface

    An interface defining the structure of the dependency monitor class. It includes properties and methods for managing the monitoring of dependencies. DependencyMonitorInterface

    interface DependencyMonitorInterface {
        checkIntervalStarted: boolean;
        getAllStatuses(): Promise<DependencyStatus[]>;
        getPrometheusMetrics(): Promise<string>;
        getPrometheusRegistry(): any;
        getStatus(dependencyName: string): Promise<DependencyStatus>;
        register(dependency: DependencyCheckOptions): void;
        startDependencyCheckInterval(): void;
        stopDependencyCheckInterval(): void;
    }

    Implemented by

    Index

    Properties

    checkIntervalStarted: boolean

    A flag indicating whether the check interval has started.

    const monitor = new DependencyMonitor();
    console.log(monitor.checkIntervalStarted); // false
    monitor.startDependencyCheckInterval();
    console.log(monitor.checkIntervalStarted); // true

    Methods

    • Retrieves the statuses of all registered dependencies.

      Returns Promise<DependencyStatus[]>

      • A promise that resolves to an array of dependency statuses.
      const statuses = await monitor.getAllStatuses();
      console.log(statuses);
      // Output:
      // [
      // { name: 'Database', healthy: true, code: 0, status: 'OK', ... },
      // { name: 'API', healthy: false, code: 1, status: 'ERROR', ... },
      // ]
    • Retrieves the Prometheus metrics for all dependencies.

      Returns Promise<string>

      • A promise that resolves to a string containing the Prometheus metrics.
      const prometheusMetrics = await monitor.getPrometheusMetrics();
      console.log(prometheusMetrics);
      // Output:
      // # HELP dependency_health The status of the database connection (0 = Healthy, 1 = Unhealthy)
      // # TYPE dependency_health gauge
      // dependency_health{dependency="Database", impact="Database info will not be available."} 0
      // # HELP dependency_latency The latency of the database connection check
      // # TYPE dependency_latency gauge
      // dependency_latency{dependency="Database"} 50
    • Returns the underlying prom-client Registry used for metrics. Metrics are always enabled; this method never returns undefined.

      Returns any

    • Retrieves the status of a specific dependency by name.

      Parameters

      • dependencyName: string

        The name of the dependency to check.

      Returns Promise<DependencyStatus>

      • A promise that resolves to the status of the specified dependency.
      const status = await monitor.getStatus('Database');
      console.log(status);
      // Output:
      // { name: 'Database', healthy: true, code: 0, status: 'OK', ... }
    • Registers a new dependency to be monitored.

      Parameters

      Returns void

      monitor.register({
      name: 'Database',
      description: 'Database connection check',
      impact: 'Database data will be unavailable.',
      check: async () => {
      // Perform some check (e.g., ping a database)
      return SUCCESS_STATUS_CODE;
      },
      });