diff --git a/python/extensions/banners/_30_system_resources.py b/python/extensions/banners/_30_system_resources.py index 51e764d63..9e1c257ef 100644 --- a/python/extensions/banners/_30_system_resources.py +++ b/python/extensions/banners/_30_system_resources.py @@ -10,15 +10,25 @@ class SystemResourcesCheck(Extension): except Exception: cpu_percent = None + try: + cpu_cores = psutil.cpu_count(logical=True) + except Exception: + cpu_cores = None + load_avg = self._get_load_average() try: vm = psutil.virtual_memory() ram_percent = vm.percent + ram_used_gb = vm.used / (1024 ** 3) + ram_total_gb = vm.total / (1024 ** 3) except Exception: ram_percent = None - disk_percent, disk_path = self._get_disk_usage_percent() + ram_used_gb = None + ram_total_gb = None + + disk_percent, disk_used_gb, disk_total_gb, disk_path = self._get_disk_usage() try: net = psutil.net_io_counters() @@ -33,12 +43,21 @@ class SystemResourcesCheck(Extension): la1, la5, la15 = load_avg load_value = f"{la1:.2f} / {la5:.2f} / {la15:.2f}" - disk_value = "N/A" - if disk_percent is not None: - disk_value = f"{disk_percent:.0f}% ({disk_path})" + if disk_percent is None or disk_used_gb is None or disk_total_gb is None: + disk_value = "N/A" + else: + disk_value = f"{disk_used_gb:.2f}/{disk_total_gb:.2f} GB" - cpu_value = "N/A" if cpu_percent is None else f"{cpu_percent:.0f}%" - ram_value = "N/A" if ram_percent is None else f"{ram_percent:.0f}%" + if cpu_percent is None: + cpu_value = "N/A" + else: + cores_value = "" if cpu_cores is None else f" ({cpu_cores} cores)" + cpu_value = f"{cpu_percent:.0f}%{cores_value}" + + if ram_percent is None or ram_used_gb is None or ram_total_gb is None: + ram_value = "N/A" + else: + ram_value = f"{ram_used_gb:.2f}/{ram_total_gb:.2f} GB" cpu_bar = self._bar_html(cpu_percent) ram_bar = self._bar_html(ram_percent) @@ -50,20 +69,32 @@ class SystemResourcesCheck(Extension): "priority": 10, "title": "System Resources", "html": ( - "
" - "
" - f"
CPU
" - f"
{cpu_value}
{cpu_bar}
" - f"
RAM
" - f"
{ram_value}
{ram_bar}
" - f"
Disk
" - f"
{disk_value}
{disk_bar}
" + "
" + "
" + "
" + "
CPU
" + f"
{cpu_value}
" + "
" + f"{cpu_bar}" + "
" + "
RAM
" + f"
{ram_value}
" + "
" + f"{ram_bar}" + "
" + "
Disk
" + f"
{disk_value}
" + "
" + f"{disk_bar}" + "
" + "
" + "
" + f"
Load (1/5/15)
{load_value}
" + f"
Net (since boot)
{net_sent} sent / {net_recv} recv
" "
" - f"
Load (1/5/15)
{load_value}
" - f"
Net (since boot)
{net_sent} sent / {net_recv} recv
" "
" ), - "dismissible": False, + "dismissible": True, "source": "backend", }) @@ -80,8 +111,8 @@ class SystemResourcesCheck(Extension): color = "#22c55e" return ( - "
" + "
" f"
" "
" ) @@ -92,14 +123,16 @@ class SystemResourcesCheck(Extension): except Exception: return None - def _get_disk_usage_percent(self) -> tuple[float | None, str]: + def _get_disk_usage(self) -> tuple[float | None, float | None, float | None, str]: for path in ["/", os.path.expanduser("~")]: try: usage = psutil.disk_usage(path) - return usage.percent, path + used_gb = usage.used / (1024 ** 3) + total_gb = usage.total / (1024 ** 3) + return usage.percent, used_gb, total_gb, path except Exception: continue - return None, "/" + return None, None, None, "/" def _format_bytes(self, value: int) -> str: size = float(value) diff --git a/webui/components/welcome/welcome-screen.html b/webui/components/welcome/welcome-screen.html index 1364c57c1..5e07ed8f4 100644 --- a/webui/components/welcome/welcome-screen.html +++ b/webui/components/welcome/welcome-screen.html @@ -50,6 +50,25 @@
+ +