2021-05-28T03:19:41.061Z INFO [monitoring] log/log.go:145 Non-zero metrics in the last 30s {"monitoring": {"metrics": {"beat":{"cpu":{"system":{"ticks":6249680,"time":{"ms":3024}},"total":{"ticks":13659880,"time":{"ms":6612},"value":13659880},"user":{"ticks":7410200,"time":{"ms":3588}}},"handles":{"limit":{"hard":1048576,"soft":1048576},"open":46},"info":{"ephemeral_id":"ca641ad8-e10a-496f-a087-6924e456aaea","uptime":{"ms":60180037}},"memstats":{"gc_next":42518272,"memory_alloc":31026880,"memory_total":1715304668248,"rss":-1552384},"runtime":{"goroutines":206}},"filebeat":{"events":{"added":139,"done":139},**"harvester":{"open_files":0,"running":0}}**,"libbeat":{"config":{"module":{"running":0}},"pipeline":{"clients":1,"events":{"active":1,"filtered":139,"total":139},"registrar":{"states":{"current":55084,"update":13},"writes":{"success":139,"total":139}},"system":{"load":{"1":9.21,"15":10.97,"5":10.87,"norm":{"1":0.3838,"15":0.4571,"5":0.4529}}}}}}
deffilter_files_by_expire_minutes() -> Generator[Path, None, None]: """Get all expired files""" now = datetime.datetime.now() for name in glob.glob(file_regex, recursive=True): file_obj = Path(name) updated = datetime.datetime.fromtimestamp(file_obj.stat().st_mtime) if updated < now - datetime.timedelta(minutes=minutes): yield file_obj
open_file_process_map = get_processes_open(file_regex) for f in filter_files_by_expire_minutes(): ifstr(f) notin open_file_process_map: logging.info(f"deleting {f}") try: f.unlink() deleted_count += 1 except Exception as e: skipped_count += 1 logging.warning("failed to delete file: %s, for: %s", str(f), e) continue else: skipped_count += 1 logging.info(f"skipping {f}, for process: {open_file_process_map[str(f)]}")