예제 #1
0
 def start(self):
     logging.info("Starting metrics logging thread...")
     if not self.thread_running:
         self.thread = threading.Timer(self.config.log_interval_sec,
                                       self._run_thread)
         self.thread.start()
         self.thread_running = True
예제 #2
0
 def _create_log_file(self):
     logging.debug(f"Creating logging file {self.metrics_log_file}...")
     if not os.path.exists(self.metrics_log_file):
         try:
             logging.info(f"Creating log file {self.metrics_log_file}")
             os.makedirs(os.path.dirname(self.metrics_log_file),
                         exist_ok=True)
             with open(self.metrics_log_file, "w") as f:
                 json.dump({}, f)
         except Exception as e:
             raise Exception(
                 f"Could not create log file {self.metrics_log_file}.\n {e}"
             )
예제 #3
0
    def _resolve_log_file(self):
        logging.debug("Resolving log file location...")
        if self.config.gdrive_log_file is not None:
            return self.config.gdrive_log_file

        remote_metrics_log_file = self.config.remote_metrics_log_file
        file_location_parts = list(filter(None, remote_metrics_log_file.split("/")))
        gdrive_loc = ""
        for part in file_location_parts[::-1]:
            gdrive_loc = f"/{part}{gdrive_loc}"
            if self.gdrive.get(gdrive_loc) is not None:
                logging.info(
                    f"Google Drive log file location resolved as {gdrive_loc}."
                )
                return gdrive_loc

        raise Exception(
            f"Could not resolve log file location from config: {remote_metrics_log_file}"
        )
예제 #4
0
 def stop(self):
     logging.info("Stopping Google Drive featching thread.")
     self.thread.cancel()
     self.thread_running = False
예제 #5
0
 def stop(self):
     logging.info("Canceling metrics logging thread...")
     self.thread.cancel()
     self.thread_running = False
예제 #6
0
 def stop(self):
     logging.info("Stopping metrics fetching threads...")