diff --git a/adguard_exporter.py b/adguard_exporter.py index ff6e81b..1b77ac5 100755 --- a/adguard_exporter.py +++ b/adguard_exporter.py @@ -150,11 +150,25 @@ def __init__(self, log_file_path, metrics_collector): self.is_initialized = False self.start_time = time.time() self.last_inode = None + self.wait_for_log_file() self.initial_load() def get_inode(self): return os.stat(self.log_file_path).st_ino if os.path.exists(self.log_file_path) else None + def wait_for_log_file(self): + max_wait_time = 120 # Maximum wait time in seconds + wait_interval = 5 # Interval between checks in seconds + start_time = time.time() + while not os.path.exists(self.log_file_path): + elapsed_time = time.time() - start_time + if elapsed_time >= max_wait_time: + logger.error(f"Log file did not appear within {max_wait_time} seconds.") + sys.exit(1) + logger.info(f"Waiting for log file to appear... ({int(elapsed_time)} seconds elapsed)") + time.sleep(wait_interval) + logger.info(f"Log file found: {self.log_file_path}") + def initial_load(self): logger.info(f"Performing initial load of log file: {self.log_file_path}") self.last_inode = self.get_inode()