uptime-monitor

This commit is contained in:
2026-08-20 09:32:04 +02:00
parent 5c6262063a
commit 0fed855cf7
12 changed files with 621 additions and 0 deletions
+61
View File
@@ -0,0 +1,61 @@
from __future__ import annotations
import logging
import os
import sys
import time
from app.checker import check_all
from app.config import ConfigError, load_config
from app.influx_writer import write_results
logger = logging.getLogger("uptime_monitor")
def setup_logging() -> None:
logging.basicConfig(
level=os.environ.get("LOG_LEVEL", "INFO"),
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
stream=sys.stdout,
)
def run_cycle(cfg) -> list:
timestamp_ns = time.time_ns()
results = check_all(cfg.endpoints, cfg.check.timeout_seconds, timestamp_ns)
write_results(cfg.influx, results)
return results
def main() -> None:
setup_logging()
config_path = os.environ.get("CONFIG_PATH", "/config/config.yaml")
try:
cfg = load_config(config_path)
except ConfigError as e:
logger.error("configuration error: %s", e)
sys.exit(1)
logger.info(
"loaded %d endpoint(s) from %s; interval=%ss, immediate recheck on failure enabled",
len(cfg.endpoints), config_path, cfg.check.interval_seconds,
)
while True:
results = run_cycle(cfg)
if any(not r.success for r in results):
logger.warning(
"at least one endpoint failed this cycle; "
"re-checking all endpoints immediately in %.0fs",
cfg.check.immediate_recheck_delay_seconds,
)
time.sleep(cfg.check.immediate_recheck_delay_seconds)
run_cycle(cfg)
time.sleep(cfg.check.interval_seconds)
if __name__ == "__main__":
main()