Health System¶
This document describes the health subsystem implemented in the current code.
Source of truth:
pytmbot/health_system/health_system.pypytmbot/parsers/health_checker.pypytmbot/main.pypytmbot/handlers/server_handlers/health_summary.py
Overview¶
The health subsystem provides:
- periodic component-level checks
- a latest-summary singleton for UI and CLI consumers
- startup and runtime health logging
- the
/healthuser-facing screen
The launcher builds the health manager after bot initialization and starts monitoring in a background thread.
Health Levels¶
Current health levels are:
healthydegradedunhealthycriticaloffline
The health summary also exposes:
health_ratiooperationaltotalduration_ms- per-component details
Registered Checkers¶
Core checkers:
telegram_apievery90secondspollingevery45secondssessionsevery60seconds when a session manager is availablesystem_resourcesevery75seconds when a psutil adapter is availabletemplate_parserevery90seconds when parser health support is importable
Health Manager Components¶
HealthMonitor: stores checker registry, latest snapshot, history, and monitor threadHealthManager: small wrapper aroundHealthMonitorHealthStatus: compatibility singleton used by UI and CLI consumers
Runtime Behavior¶
The launcher:
- creates a configured
HealthManager - publishes it into
HealthStatus - starts monitoring with a base interval of
120seconds - logs state changes and periodic status summaries
Health system failures do not abort bot startup. They are logged and the bot continues without health monitoring.
CLI Health Check¶
The application CLI exposes:
uv run python pytmbot/main.py --health_check
Exit codes:
0: healthy1: unhealthy / degraded result exposed as falsey compatibility status2: no health manager data available
Note:
--health_checkreports the current in-processHealthStatuscompatibility value. It is not a standalone probe that bootstraps the full runtime by itself.
UI Consumption¶
The server health handler reads HealthStatus().get_summary() and renders a Telegram health snapshot from the latest
monitor data.