Skip to content

Commit

Permalink
fix: revert code and set default CPU reporting to be True
Browse files Browse the repository at this point in the history
  • Loading branch information
duongtn811 committed Sep 7, 2024
1 parent 4165fea commit 1d0fdaa
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
25 changes: 13 additions & 12 deletions jupyter_resource_usage/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@ async def get(self):

metrics = {"rss": rss, "limits": limits}

# Always get cpu usage information
cpu_count = psutil.cpu_count()
cpu_percent = await self._get_cpu_percent(all_processes)

if config.cpu_limit != 0:
limits["cpu"] = {"cpu": config.cpu_limit}
if config.cpu_warning_threshold != 0:
limits["cpu"]["warn"] = (config.cpu_limit - cpu_percent) < (
config.cpu_limit * config.cpu_warning_threshold
)

metrics.update(cpu_percent=cpu_percent, cpu_count=cpu_count)
# Optionally get CPU information
if config.track_cpu_percent:
cpu_count = psutil.cpu_count()
cpu_percent = await self._get_cpu_percent(all_processes)

if config.cpu_limit != 0:
limits["cpu"] = {"cpu": config.cpu_limit}
if config.cpu_warning_threshold != 0:
limits["cpu"]["warn"] = (config.cpu_limit - cpu_percent) < (
config.cpu_limit * config.cpu_warning_threshold
)

metrics.update(cpu_percent=cpu_percent, cpu_count=cpu_count)

self.write(json.dumps(metrics))

Expand Down
4 changes: 2 additions & 2 deletions jupyter_resource_usage/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ def _mem_limit_default(self):
return int(os.environ.get("MEM_LIMIT", 0))

track_cpu_percent = Bool(
default_value=False,
default_value=True,
help="""
Set to True in order to enable reporting of CPU usage statistics.
Set to False in order to disable reporting of CPU usage statistics.
""",
).tag(config=True)

Expand Down

0 comments on commit 1d0fdaa

Please sign in to comment.