Skip to main content

Class: MonitorManager

Defined in: electron/managers/MonitorManager.ts:167

Main class for orchestrating monitor scheduling, status checks, and event-driven updates.

Remarks

All monitoring operations, including lifecycle management, scheduling, and event emission, are coordinated here. This class is the central entry point for all backend monitoring logic.

Constructors

Constructor

new MonitorManager(dependencies: MonitorManagerDependencies, enhancedServices: EnhancedMonitoringServices): MonitorManager

Defined in: electron/managers/MonitorManager.ts:1004

Constructs a new MonitorManager instance with enhanced monitoring capabilities.

Parameters

dependencies

MonitorManagerDependencies

The required MonitorManagerDependencies for orchestration and data access

enhancedServices

EnhancedMonitoringServices

The required EnhancedMonitoringServices for advanced monitoring capabilities

Returns

MonitorManager

Remarks

All dependencies are injected to support testability and separation of concerns. The enhanced monitoring services are required and provide race condition prevention, operation correlation, and advanced timeout management for all monitoring operations.

Architecture Integration:

  • Enhanced services are always provided by the ServiceContainer
  • No fallback to legacy monitoring systems
  • All monitoring operations use the unified enhanced system
  • Operation correlation prevents race conditions across concurrent operations

Examples

const manager = new MonitorManager(dependencies, enhancedServices);
const container = ServiceContainer.getInstance();
const manager = container.getMonitorManager();
// Enhanced services are automatically provided

See

Properties

dependencies

readonly dependencies: MonitorManagerDependencies

Defined in: electron/managers/MonitorManager.ts:175

Injected dependencies for orchestration and data access.


enhancedMonitoringServices

private readonly enhancedMonitoringServices: EnhancedMonitoringServices

Defined in: electron/managers/MonitorManager.ts:185

Enhanced monitoring services for race condition prevention.

Remarks

Provides operation correlation and state-aware monitoring operations.


eventEmitter

readonly eventEmitter: TypedEventBus<UptimeEvents>

Defined in: electron/managers/MonitorManager.ts:194

Event bus for monitor events.


isMonitoring

isMonitoring: boolean = false

Defined in: electron/managers/MonitorManager.ts:206

Indicates if monitoring is currently active for any site or monitor.

Remarks

Used to track the global monitoring state.

Default Value

false

@public

monitorScheduler

readonly monitorScheduler: MonitorScheduler

Defined in: electron/managers/MonitorManager.ts:218

Scheduler for monitor intervals and checks.

Remarks

Handles scheduling and execution of periodic monitor checks.

Methods

checkSiteManually()

checkSiteManually(identifier: string, monitorId?: string): Promise<undefined | StatusUpdate>

Defined in: electron/managers/MonitorManager.ts:248

Manually checks a site or monitor and returns the resulting status update.

Parameters

identifier

string

The site identifier to check.

monitorId?

string

Optional monitor ID for targeted check.

Returns

Promise<undefined | StatusUpdate>

The StatusUpdate for the site or monitor, or undefined if not found.

Remarks

Triggers a manual check for a site or monitor, emits a completion event, and returns the result. Uses the repository and event-driven patterns for all operations.

Example

const update = await manager.checkSiteManually("site-123", "monitor-456");

Throws

Any error encountered during the check is logged and re-thrown.


setupNewMonitors()

setupNewMonitors(site: Site, newMonitorIds: string[]): Promise<void>

Defined in: electron/managers/MonitorManager.ts:325

Sets up new monitors that were added to an existing site.

Parameters

site

Site

The Site containing the new monitors.

newMonitorIds

string[]

Array of new monitor IDs to set up.

Returns

Promise<void>

A promise that resolves when setup is complete.

Remarks

Ensures new monitors receive the same initialization as those in new sites, including default interval assignment and auto-start logic.

Example

await manager.setupNewMonitors(siteObj, ["monitor-1", "monitor-2"]);

Throws

Any error encountered during setup is logged and re-thrown.


setupSiteForMonitoring()

setupSiteForMonitoring(site: Site): Promise<void>

Defined in: electron/managers/MonitorManager.ts:387

Sets up a new site for monitoring, including initial checks, interval assignment, and auto-start logic.

Parameters

site

Site

The Site to set up for monitoring.

Returns

Promise<void>

A promise that resolves when setup is complete.

Remarks

Applies business rules for default intervals and auto-starting monitoring. Initial checks are handled by MonitorScheduler when monitoring starts.

Example

await manager.setupSiteForMonitoring(siteObj);

Throws

Any error encountered during setup is logged and re-thrown.


startMonitoring()

startMonitoring(): Promise<void>

Defined in: electron/managers/MonitorManager.ts:426

Starts monitoring for all sites.

Returns

Promise<void>

A promise that resolves when monitoring has started.

Remarks

Initiates monitoring for all sites and emits a monitoring started event. Uses the repository and event-driven patterns for all operations.

Example

await manager.startMonitoring();

Throws

Any error encountered during start is logged and re-thrown.


startMonitoringForSite()

startMonitoringForSite(identifier: string, monitorId?: string): Promise<boolean>

Defined in: electron/managers/MonitorManager.ts:478

Starts monitoring for a specific site or monitor.

Parameters

identifier

string

The site identifier to start monitoring for.

monitorId?

string

Optional monitor ID for targeted monitoring.

Returns

Promise<boolean>

true if monitoring started successfully, false otherwise.

Remarks

Initiates monitoring for a site or monitor and emits a started event. Handles recursive calls to avoid infinite loops.

Example

const started = await manager.startMonitoringForSite("site-123", "monitor-456");

Throws

Any error encountered during start is logged and re-thrown.


stopMonitoring()

stopMonitoring(): Promise<void>

Defined in: electron/managers/MonitorManager.ts:554

Stops monitoring for all sites.

Returns

Promise<void>

A promise that resolves when monitoring has stopped.

Remarks

Stops all monitoring and emits a monitoring stopped event. Uses the repository and event-driven patterns for all operations.

Example

await manager.stopMonitoring();

Throws

Any error encountered during stop is logged and re-thrown.


stopMonitoringForSite()

stopMonitoringForSite(identifier: string, monitorId?: string): Promise<boolean>

Defined in: electron/managers/MonitorManager.ts:599

Stops monitoring for a specific site or monitor.

Parameters

identifier

string

The site identifier to stop monitoring for.

monitorId?

string

Optional monitor ID for targeted stop.

Returns

Promise<boolean>

true if monitoring stopped successfully, false otherwise.

Remarks

Stops monitoring for a site or monitor and emits a stopped event. Handles recursive calls to avoid infinite loops.

Example

const stopped = await manager.stopMonitoringForSite("site-123", "monitor-456");

Throws

Any error encountered during stop is logged and re-thrown.


applyDefaultIntervals()

private applyDefaultIntervals(site: Site): Promise<void>

Defined in: electron/managers/MonitorManager.ts:676

Internal

Applies default check intervals for monitors that do not have one set.

Parameters

site

Site

The Site whose monitors should be checked for default interval assignment.

Returns

Promise<void>

A promise that resolves when all applicable monitors have been updated.

Remarks

Ensures all monitors have a check interval set according to business rules. Updates the database first, then allows the cache/state to be updated through proper channels.

Throws

Any error encountered during database update is logged and re-thrown.


autoStartMonitoringIfAppropriate()

private autoStartMonitoringIfAppropriate(site: Site): Promise<void>

Defined in: electron/managers/MonitorManager.ts:753

Internal

Automatically starts monitoring if appropriate according to business rules.

Parameters

site

Site

The Site to evaluate for auto-start.

Returns

Promise<void>

A promise that resolves when auto-start logic is complete.

Remarks

Site-level monitoring acts as a master switch. Only monitors with monitoring enabled are started.


autoStartNewMonitors()

private autoStartNewMonitors(site: Site, newMonitors: Monitor[]): Promise<void>

Defined in: electron/managers/MonitorManager.ts:836

Internal

Auto-starts monitoring for new monitors if appropriate.

Parameters

site

Site

The Site containing the new monitors.

newMonitors

Monitor[]

Array of new monitors to potentially auto-start.

Returns

Promise<void>

A promise that resolves when auto-start logic is complete.

Remarks

Only monitors with monitoring enabled will be auto-started.


handleScheduledCheck()

private handleScheduledCheck(siteIdentifier: string, monitorId: string): Promise<void>

Defined in: electron/managers/MonitorManager.ts:879

Internal

Handles scheduled monitor checks from the MonitorScheduler.

Parameters

siteIdentifier

string

The identifier of the site.

monitorId

string

The monitor ID to check.

Returns

Promise<void>

A promise that resolves when the scheduled check is complete.

Remarks

Invoked by the scheduler to perform a check on a specific monitor at the scheduled interval.


setupIndividualNewMonitors()

private setupIndividualNewMonitors(site: Site, newMonitors: Monitor[]): Promise<void>

Defined in: electron/managers/MonitorManager.ts:928

Internal

Sets up individual new monitors.

Parameters

site

Site

The Site containing the new monitors.

newMonitors

Monitor[]

Array of new monitors to set up.

Returns

Promise<void>

A promise that resolves when setup is complete.

Remarks

New monitors are handled differently as they have not been persisted yet. Default intervals are applied directly to the monitor objects before they are saved to the database. Auto-start logic is also applied if appropriate.


getActiveMonitorCount()

getActiveMonitorCount(): number

Defined in: electron/managers/MonitorManager.ts:1034

Gets the count of active monitors currently being scheduled.

Returns

number

The number of active monitors in the scheduler.

Remarks

Returns the number of monitors that are currently scheduled for periodic checks.

Example

const count = manager.getActiveMonitorCount();

isMonitorActiveInScheduler()

isMonitorActiveInScheduler(siteIdentifier: string, monitorId: string): boolean

Defined in: electron/managers/MonitorManager.ts:1062

Checks if a specific monitor is actively being scheduled for checks.

Parameters

siteIdentifier

string

The identifier of the site.

monitorId

string

The monitor ID to check.

Returns

boolean

true if the monitor is active in the scheduler, false otherwise.

Remarks

Returns whether the given monitor is currently scheduled for periodic checks by the scheduler.

Example

const isActive = manager.isMonitorActiveInScheduler("site-123", "monitor-456");

isMonitoringActive()

isMonitoringActive(): boolean

Defined in: electron/managers/MonitorManager.ts:1079

Indicates whether monitoring is currently active for any site or monitor.

Returns

boolean

true if monitoring is active, false otherwise.

Remarks

Returns the global monitoring state.


restartMonitorWithNewConfig()

restartMonitorWithNewConfig(siteIdentifier: string, monitor: Monitor): boolean

Defined in: electron/managers/MonitorManager.ts:1109

Restarts monitoring for a specific monitor with updated configuration.

Parameters

siteIdentifier

string

The identifier of the site containing the monitor.

monitor

Monitor

The monitor object with updated configuration.

Returns

boolean

true if the monitor was successfully restarted, false otherwise.

Remarks

Useful when monitor intervals or settings change and need immediate application. Delegates to the MonitorScheduler for actual restart logic.

Example

const success = manager.restartMonitorWithNewConfig("site-123", monitorObj);

shouldApplyDefaultInterval()

private shouldApplyDefaultInterval(monitor: Monitor): boolean

Defined in: electron/managers/MonitorManager.ts:1132

Internal

Determines if a monitor should receive a default interval.

Parameters

monitor

Monitor

The monitor to check for default interval application.

Returns

boolean

true if the monitor should receive the default interval, false otherwise.

Remarks

Checks for falsy checkInterval values. Zero is considered a valid interval and will not trigger default assignment. The type system guarantees checkInterval is a number, but runtime values may still be falsy due to initialization or data import scenarios.