Skip to content

Commit 1d0fdaa

Browse files
committed
fix: revert code and set default CPU reporting to be True
1 parent 4165fea commit 1d0fdaa

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

jupyter_resource_usage/api.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,19 @@ async def get(self):
4747

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

50-
# Always get cpu usage information
51-
cpu_count = psutil.cpu_count()
52-
cpu_percent = await self._get_cpu_percent(all_processes)
53-
54-
if config.cpu_limit != 0:
55-
limits["cpu"] = {"cpu": config.cpu_limit}
56-
if config.cpu_warning_threshold != 0:
57-
limits["cpu"]["warn"] = (config.cpu_limit - cpu_percent) < (
58-
config.cpu_limit * config.cpu_warning_threshold
59-
)
60-
61-
metrics.update(cpu_percent=cpu_percent, cpu_count=cpu_count)
50+
# Optionally get CPU information
51+
if config.track_cpu_percent:
52+
cpu_count = psutil.cpu_count()
53+
cpu_percent = await self._get_cpu_percent(all_processes)
54+
55+
if config.cpu_limit != 0:
56+
limits["cpu"] = {"cpu": config.cpu_limit}
57+
if config.cpu_warning_threshold != 0:
58+
limits["cpu"]["warn"] = (config.cpu_limit - cpu_percent) < (
59+
config.cpu_limit * config.cpu_warning_threshold
60+
)
61+
62+
metrics.update(cpu_percent=cpu_percent, cpu_count=cpu_count)
6263

6364
self.write(json.dumps(metrics))
6465

jupyter_resource_usage/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ def _mem_limit_default(self):
8787
return int(os.environ.get("MEM_LIMIT", 0))
8888

8989
track_cpu_percent = Bool(
90-
default_value=False,
90+
default_value=True,
9191
help="""
92-
Set to True in order to enable reporting of CPU usage statistics.
92+
Set to False in order to disable reporting of CPU usage statistics.
9393
""",
9494
).tag(config=True)
9595

0 commit comments

Comments
 (0)