Skip to content

Commit

Permalink
feat(ingest): Track disk usage in report (#7812)
Browse files Browse the repository at this point in the history
  • Loading branch information
asikowitz authored Apr 13, 2023
1 parent 4742e81 commit ce79540
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions metadata-ingestion/src/datahub/ingestion/run/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import os
import platform
import shutil
import sys
import time
from dataclasses import dataclass
Expand Down Expand Up @@ -128,14 +129,30 @@ class CliReport(Report):
py_exec_path: str = sys.executable
os_details: str = platform.platform()
_peak_memory_usage: int = 0
_peak_disk_usage: int = 0

def compute_stats(self) -> None:
mem_usage = psutil.Process(os.getpid()).memory_info().rss
if self._peak_memory_usage < mem_usage:
self._peak_memory_usage = mem_usage
self.peak_memory_usage = humanfriendly.format_size(self._peak_memory_usage)
try:
mem_usage = psutil.Process(os.getpid()).memory_info().rss
if self._peak_memory_usage < mem_usage:
self._peak_memory_usage = mem_usage
self.peak_memory_usage = humanfriendly.format_size(
self._peak_memory_usage
)
self.mem_info = humanfriendly.format_size(mem_usage)

disk_usage = shutil.disk_usage("/")
if self._peak_disk_usage < disk_usage.used:
self._peak_disk_usage = disk_usage.used
self.peak_disk_usage = humanfriendly.format_size(self._peak_disk_usage)
self.disk_info = {
"total": humanfriendly.format_size(disk_usage.total),
"used": humanfriendly.format_size(disk_usage.used),
"free": humanfriendly.format_size(disk_usage.free),
}
except Exception as e:
logger.warning(f"Failed to compute report memory usage: {e}")

self.mem_info = humanfriendly.format_size(mem_usage)
return super().compute_stats()


Expand Down

0 comments on commit ce79540

Please sign in to comment.