Creates an instance of DependencyMonitor.
Optional
options: DependencyMonitorOptions = {}Optional configuration options for the monitor.
A flag indicating whether the check interval has started.
Retrieves the statuses of all registered dependencies.
Retrieves the Prometheus metrics for all dependencies.
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
Retrieves the status of a specific dependency by name.
The name of the dependency to check.
Registers a new dependency to be monitored.
The dependency to register.
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. DependencyMonitor