From 78ea1067c0d39a0787a8252de2475333d20bbc93 Mon Sep 17 00:00:00 2001 From: Janaka-Steph Date: Fri, 3 Nov 2023 11:45:41 +0100 Subject: [PATCH 1/4] New GPU stats api --- docker-compose.gateway.yml | 1 - src/controller/abstractServiceController.ts | 4 +- src/controller/binariesController.ts | 6 +- src/controller/dockerController.ts | 4 +- src/controller/serviceController.ts | 7 +-- src/modules/service/types.ts | 16 ++++- .../settings/components/GPUResources.tsx | 60 ++++++++++--------- 7 files changed, 55 insertions(+), 43 deletions(-) diff --git a/docker-compose.gateway.yml b/docker-compose.gateway.yml index 6fedfd79..129d0ff9 100644 --- a/docker-compose.gateway.yml +++ b/docker-compose.gateway.yml @@ -5,7 +5,6 @@ services: container_name: premapp build: . environment: - - VITE_DESTINATION=browser - VITE_IS_PACKAGED=true - VITE_PROXY_ENABLED=true labels: diff --git a/src/controller/abstractServiceController.ts b/src/controller/abstractServiceController.ts index 98b93e04..64561d7e 100644 --- a/src/controller/abstractServiceController.ts +++ b/src/controller/abstractServiceController.ts @@ -1,4 +1,4 @@ -import type { Service } from "../modules/service/types"; +import type { GPUStats, Service } from "../modules/service/types"; import type { Interface } from "../shared/helpers/interfaces"; import type { DownloadArgs } from "./serviceController"; @@ -20,7 +20,7 @@ abstract class AbstractServiceController { abstract getLogs(serviceId: string): Promise; abstract getServiceStats(serviceId: string): Promise>; abstract getSystemStats(): Promise>; - abstract getGPUStats(): Promise>; + abstract getGPUStats(): Promise; abstract getInterfaces(): Promise; abstract addService(service: Service): Promise; } diff --git a/src/controller/binariesController.ts b/src/controller/binariesController.ts index 8ebca0af..7ac3c5b9 100644 --- a/src/controller/binariesController.ts +++ b/src/controller/binariesController.ts @@ -1,6 +1,6 @@ import { invoke } from "@tauri-apps/api/tauri"; -import type { Service, ServiceBinary } from "../modules/service/types"; +import type { GPUStats, Service, ServiceBinary } from "../modules/service/types"; import type { Interface } from "../shared/helpers/interfaces"; import interfaces from "../shared/helpers/interfaces"; @@ -58,8 +58,8 @@ class BinariesController extends AbstractServiceController { return await invoke("get_logs_for_service", { serviceId }); } - async getGPUStats(): Promise> { - return await invoke>("get_gpu_stats"); + async getGPUStats(): Promise { + return await invoke("get_gpu_stats"); } async getServiceStats(serviceId: string): Promise> { diff --git a/src/controller/dockerController.ts b/src/controller/dockerController.ts index 839730bd..27899462 100644 --- a/src/controller/dockerController.ts +++ b/src/controller/dockerController.ts @@ -1,5 +1,5 @@ import downloadServiceStream from "../modules/service/api/downloadServiceStream"; -import type { Service, ServiceDocker } from "../modules/service/types"; +import type { GPUStats, Service, ServiceDocker } from "../modules/service/types"; import api from "../shared/api/v1"; import type { Interface } from "../shared/helpers/interfaces"; import useSettingStore from "../shared/store/setting"; @@ -81,7 +81,7 @@ class DockerController extends AbstractServiceController { return response.data; } - async getGPUStats(): Promise> { + async getGPUStats(): Promise { const response = await api().get("v1/gpu-stats-all/"); return response.data; } diff --git a/src/controller/serviceController.ts b/src/controller/serviceController.ts index 6a61ceec..3f4a7e54 100644 --- a/src/controller/serviceController.ts +++ b/src/controller/serviceController.ts @@ -1,4 +1,4 @@ -import type { Service } from "../modules/service/types"; +import type { GPUStats, Service } from "../modules/service/types"; import type { Interface } from "../shared/helpers/interfaces"; import useSettingStore from "../shared/store/setting"; @@ -177,15 +177,14 @@ class ServiceController implements IServiceController { return {}; } } - - async getGPUStats(serviceType: Service["serviceType"]): Promise> { + async getGPUStats(serviceType: Service["serviceType"]): Promise { // We check the env (browser or desktop) to determine serviceType if (serviceType === "docker") { return await this.dockerController.getGPUStats(); } else if (serviceType === "binary") { return await this.binariesController.getGPUStats(); } else { - return {}; + return {} as GPUStats; } } diff --git a/src/modules/service/types.ts b/src/modules/service/types.ts index 0d219885..159418cf 100644 --- a/src/modules/service/types.ts +++ b/src/modules/service/types.ts @@ -81,12 +81,24 @@ export type Stats = { storage_percentage: number; }; +type GPUInfos = { + gpu_name: string; + total_memory: number; + used_memory: number; + free_memory: number; + utilised_memory: number; + load: number; +}; + export type GPUStats = { - gpu_name: string | null; total_memory: number | null; used_memory: number | null; - memory_percentage: number | null; + free_memory: number | null; + average_utilised_memory: number | null; + average_load: number | null; + gpus: GPUInfos[]; }; + export type Message = { message: string; }; diff --git a/src/modules/settings/components/GPUResources.tsx b/src/modules/settings/components/GPUResources.tsx index 7da8b442..a2ffddad 100644 --- a/src/modules/settings/components/GPUResources.tsx +++ b/src/modules/settings/components/GPUResources.tsx @@ -3,40 +3,42 @@ import useGPUStats from "shared/hooks/useGPUStats"; const GPUResources = () => { const { data } = useGPUStats(); + console.log("data", data); + return ( <>

GPUs

- {data?.gpu_name ? ( -
-
- nvidia-logo -
-
-

{data.gpu_name}

-
    -
  • -
    - Memory  - - {data.used_memory} / {data.total_memory} GiB - -
    -
    -
    -
    -
  • -
+ {data?.gpus?.map((gpu) => { + return ( +
+
+ nvidia-logo +
+
+

{gpu.gpu_name}

+
    +
  • +
    + Memory  + + {gpu.used_memory} / {gpu.total_memory} GiB + +
    +
    +
    +
    +
  • +
+
-
- ) : ( -

No GPUs available

- )} + ); + }) ??

No GPUs available

}
); From 4ae04332d7b66aeff158f38d1bad3757e7acaefc Mon Sep 17 00:00:00 2001 From: Janaka-Steph Date: Fri, 3 Nov 2023 11:47:22 +0100 Subject: [PATCH 2/4] put back useless var --- docker-compose.gateway.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.gateway.yml b/docker-compose.gateway.yml index 129d0ff9..6fedfd79 100644 --- a/docker-compose.gateway.yml +++ b/docker-compose.gateway.yml @@ -5,6 +5,7 @@ services: container_name: premapp build: . environment: + - VITE_DESTINATION=browser - VITE_IS_PACKAGED=true - VITE_PROXY_ENABLED=true labels: From 8602ff92bb37d3bc6bb4ec3806ec01bd3e393a60 Mon Sep 17 00:00:00 2001 From: Janaka-Steph Date: Fri, 3 Nov 2023 11:48:15 +0100 Subject: [PATCH 3/4] rm log --- src/modules/settings/components/GPUResources.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/modules/settings/components/GPUResources.tsx b/src/modules/settings/components/GPUResources.tsx index a2ffddad..b522cc71 100644 --- a/src/modules/settings/components/GPUResources.tsx +++ b/src/modules/settings/components/GPUResources.tsx @@ -3,7 +3,6 @@ import useGPUStats from "shared/hooks/useGPUStats"; const GPUResources = () => { const { data } = useGPUStats(); - console.log("data", data); return ( <> From 91e5e0280498b99a2eb90bc82c89f992141156d0 Mon Sep 17 00:00:00 2001 From: Janaka-Steph Date: Thu, 9 Nov 2023 09:58:15 +0000 Subject: [PATCH 4/4] Add type --- src/controller/serviceController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controller/serviceController.ts b/src/controller/serviceController.ts index 23e0820a..3ac720e5 100644 --- a/src/controller/serviceController.ts +++ b/src/controller/serviceController.ts @@ -31,7 +31,7 @@ interface IServiceController { getLogs(serviceId: string, serviceType: Service["serviceType"]): Promise; getServiceStats(serviceId: string, serviceType: Service["serviceType"]): Promise; getSystemStats(serviceType: Service["serviceType"]): Promise; - getGPUStats(serviceType: Service["serviceType"]): Promise; + getGPUStats(serviceType: Service["serviceType"]): Promise; getInterfaces(serviceType: Service["serviceType"]): Promise; addService(service: Service, serviceType: Service["serviceType"]): Promise; addRegistry(registry: Registry, serviceType: Service["serviceType"]): Promise;