From 4165fea4c79cf3258bdcc5944763eb4c0dab4597 Mon Sep 17 00:00:00 2001 From: Admin Date: Fri, 21 Oct 2022 22:51:15 +0700 Subject: [PATCH 1/2] fix: always get cpu usage --- jupyter_resource_usage/api.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/jupyter_resource_usage/api.py b/jupyter_resource_usage/api.py index 2670bd8..c0587ed 100644 --- a/jupyter_resource_usage/api.py +++ b/jupyter_resource_usage/api.py @@ -47,19 +47,18 @@ async def get(self): metrics = {"rss": rss, "limits": limits} - # 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) + # 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) self.write(json.dumps(metrics)) From 1d0fdaa1bfab9446943ef899ebf714211eff8a1b Mon Sep 17 00:00:00 2001 From: duongtn811 Date: Sat, 7 Sep 2024 10:01:39 +0700 Subject: [PATCH 2/2] fix: revert code and set default CPU reporting to be True --- jupyter_resource_usage/api.py | 25 +++++++++++++------------ jupyter_resource_usage/config.py | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/jupyter_resource_usage/api.py b/jupyter_resource_usage/api.py index c0587ed..2670bd8 100644 --- a/jupyter_resource_usage/api.py +++ b/jupyter_resource_usage/api.py @@ -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)) diff --git a/jupyter_resource_usage/config.py b/jupyter_resource_usage/config.py index e8622bf..a047ebd 100644 --- a/jupyter_resource_usage/config.py +++ b/jupyter_resource_usage/config.py @@ -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)