import time import logging from app import load_config, get_remote_temperature from database import TemperatureDB # Налаштування логування logging.basicConfig( level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s' ) def collect_temperatures(): db = TemperatureDB() logging.info("Starting temperature collector") while True: try: config = load_config("config.json") for device in config.get("devices", []): host = device.get("host") username = device.get("username") password = device.get("password") if host and username and password: logging.debug(f"Collecting temperature for {host}") temp_data = get_remote_temperature(host, username, password) if temp_data['temp'] is not None: logging.info(f"Got temperature for {host}: GPU={temp_data['temp']}°C, CPU={temp_data['cpu_temp']}°C") try: db.add_temperature( host=host, gpu_temp=temp_data['temp'], cpu_temp=temp_data['cpu_temp'] ) logging.debug(f"Successfully saved temperature for {host}") except Exception as e: logging.error(f"Failed to save temperature for {host}: {e}") else: logging.warning(f"No temperature data received for {host}") except Exception as e: logging.error(f"Error in collector main loop: {e}") time.sleep(10) if __name__ == "__main__": collect_temperatures()