maple.utils.health.HealthMonitor

class maple.utils.health.HealthMonitor(check_interval: float = 30.0, on_unhealthy: Callable[[MonitoredContainer], None] | None = None)

Thread-safe health monitor for Docker containers.

Runs a background daemon thread that periodically checks the health of registered containers. Supports automatic restart on failure, custom health check callbacks, and real-time status reporting.

The monitor runs continuously once started and checks all registered containers at the specified interval. Containers are marked unhealthy after a configurable number of consecutive failures.

Thread-safety: All public methods are thread-safe and can be called from multiple threads concurrently.

Methods

__init__([check_interval, on_unhealthy])

Initialize the HealthMonitor.

check_now(container_id)

Manually trigger an immediate health check for a container.

get_all_status()

Get status of all monitored containers.

get_status(container_id)

Get current status of a specific monitored container.

register(container_id, name, check_fn[, ...])

Register a container for health monitoring.

start()

Start the health monitoring background thread.

stop()

Stop the health monitoring background thread.

unregister(container_id)

Unregister a container from health monitoring.

Attributes

is_running

Check if the health monitor is currently running.