diff --git a/backend/src/backend/user_session/routers/general.py b/backend/src/backend/user_session/routers/general.py index b28c579d5..3d1fd4566 100644 --- a/backend/src/backend/user_session/routers/general.py +++ b/backend/src/backend/user_session/routers/general.py @@ -10,13 +10,8 @@ START_TIME_CONTAINER = datetime.datetime.now() -def human_readable(psutil_object: NamedTuple) -> Dict[str, Union[str, Dict[str, str]]]: - return { - key: f"{getattr(psutil_object, key):.1f} %" - if key == "percent" - else f"{getattr(psutil_object, key) / (1024**3):.2f} GiB" - for key in psutil_object._fields - } +def _convert_psutil_object_to_dict(psutil_object: NamedTuple) -> Dict[str, Union[str, Dict[str, str]]]: + return {key: getattr(psutil_object, key) for key in psutil_object._fields} @router.get("/user_session_container") @@ -34,8 +29,9 @@ async def user_session_container( return { "username": authenticated_user.get_username(), - "start_time_container": START_TIME_CONTAINER, - "root_disk_system": human_readable(psutil.disk_usage("/")), - "memory_system": human_readable(psutil.virtual_memory()), - "memory_python_process": human_readable(psutil.Process().memory_info()), + "startTimeContainer": START_TIME_CONTAINER, + "rootDiskSystem": _convert_psutil_object_to_dict(psutil.disk_usage("/")), + "memorySystem": _convert_psutil_object_to_dict(psutil.virtual_memory()), + "memoryPythonProcess": _convert_psutil_object_to_dict(psutil.Process().memory_info()), + "cpuPercent": psutil.cpu_percent(), } diff --git a/frontend/src/framework/internal/components/NavBar/navBar.tsx b/frontend/src/framework/internal/components/NavBar/navBar.tsx index 9645ecfb8..ced78e283 100644 --- a/frontend/src/framework/internal/components/NavBar/navBar.tsx +++ b/frontend/src/framework/internal/components/NavBar/navBar.tsx @@ -16,7 +16,6 @@ import { resolveClassNames } from "@lib/utils/resolveClassNames"; import { ChevronLeft, ChevronRight, - GitHub, GridView, Link, List, @@ -26,6 +25,8 @@ import { } from "@mui/icons-material"; import { useQueryClient } from "@tanstack/react-query"; +import { UserSessionState } from "./private-components/UserSessionState"; + type NavBarProps = { workbench: Workbench; }; @@ -249,17 +250,10 @@ export const NavBar: React.FC = (props) => {
- - +
+ + +
{ensembleDialogOpen && ( diff --git a/frontend/src/framework/internal/components/NavBar/private-components/UserSessionState.tsx b/frontend/src/framework/internal/components/NavBar/private-components/UserSessionState.tsx new file mode 100644 index 000000000..a0a71a129 --- /dev/null +++ b/frontend/src/framework/internal/components/NavBar/private-components/UserSessionState.tsx @@ -0,0 +1,23 @@ +import { Memory } from "@mui/icons-material"; +import { useQuery } from "@tanstack/react-query"; + +import { apiService } from "@framework/ApiService"; + +const useUserSessionState = () => useQuery({ + queryKey: ["default.userSessionContainer"], + queryFn: () => apiService.default.userSessionContainer(), + refetchInterval: 2000 +}); + +export const UserSessionState = ({expanded}: {expanded: boolean}) => { + + const sessionState = useUserSessionState(); + + const memoryPercent = Math.round(sessionState.data?.memorySystem?.percent) || "-" + const cpuPercent = Math.round(sessionState.data?.cpuPercent) || "-" + + return
+
{expanded ? "Memory:" : "M"} {memoryPercent} %
+
{expanded ? "CPU:" : "C"} {cpuPercent} %
+
+}