From d1e89fd0d85b9a604e2a685d7cafbc69e8cb1ea4 Mon Sep 17 00:00:00 2001 From: Only-bottle Date: Thu, 5 Dec 2024 16:55:48 +0900 Subject: [PATCH 1/2] Add get_installed_libraries for server info --- app/api/v1/endpoints/system.py | 5 +++-- app/services/__init__.py | 0 app/services/system.py | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 app/services/__init__.py create mode 100644 app/services/system.py diff --git a/app/api/v1/endpoints/system.py b/app/api/v1/endpoints/system.py index 82ba5ff9..3faefd39 100644 --- a/app/api/v1/endpoints/system.py +++ b/app/api/v1/endpoints/system.py @@ -4,18 +4,19 @@ from app.api.v1.schemas.system import ( GpuInfoPayload, GpuInfosResponse, - LibraryInfo, ServerInfoPayload, ServerInfoResponse, ) +from app.services.system import system_service router = APIRouter() @router.get("/server-info", response_model=ServerInfoResponse) def get_server_info() -> ServerInfoResponse: + installed_libraries = system_service.get_installed_libraries() - server_info = ServerInfoPayload(installed_libraries=[LibraryInfo(name="netspresso", version="1.14.0")]) + server_info = ServerInfoPayload(installed_libraries=installed_libraries) return ServerInfoResponse(data=server_info) diff --git a/app/services/__init__.py b/app/services/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/app/services/system.py b/app/services/system.py new file mode 100644 index 00000000..3123b09b --- /dev/null +++ b/app/services/system.py @@ -0,0 +1,19 @@ +from typing import List + +from app.api.v1.schemas.system import LibraryInfo +from netspresso.clients.utils.system import get_package_version + + +class SystemService: + def get_installed_libraries(self) -> List[LibraryInfo]: + LIBRARY_KEYS = ["netspresso"] + + installed_libraries = [ + LibraryInfo(name=library_name, version=get_package_version(package_name=library_name)) + for library_name in LIBRARY_KEYS + ] + + return installed_libraries + + +system_service = SystemService() From 38019093a779ccdc6c688d1e52eb36a3e4b9d283 Mon Sep 17 00:00:00 2001 From: Only-bottle Date: Thu, 5 Dec 2024 18:02:04 +0900 Subject: [PATCH 2/2] Add get_gpus_info to system_service --- app/api/v1/endpoints/system.py | 35 +++++++--------------------------- app/api/v1/schemas/system.py | 2 +- app/services/system.py | 28 ++++++++++++++++++++++++++- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/app/api/v1/endpoints/system.py b/app/api/v1/endpoints/system.py index 3faefd39..78865cf0 100644 --- a/app/api/v1/endpoints/system.py +++ b/app/api/v1/endpoints/system.py @@ -1,9 +1,7 @@ from fastapi import APIRouter -from gpustat import GPUStatCollection from app.api.v1.schemas.system import ( - GpuInfoPayload, - GpuInfosResponse, + GpusInfoResponse, ServerInfoPayload, ServerInfoResponse, ) @@ -21,28 +19,9 @@ def get_server_info() -> ServerInfoResponse: return ServerInfoResponse(data=server_info) -@router.get("/gpu-info", response_model=GpuInfosResponse) -def get_gpu_infos() -> GpuInfosResponse: - - stats = GPUStatCollection.new_query() - - gpu_infos = [ - GpuInfoPayload( - index=gpu.index, - uuid=gpu.uuid, - name=gpu.name, - temperature_gpu=gpu.temperature, - fan_speed=gpu.fan_speed, - utilization_gpu=gpu.utilization, - utilization_enc=gpu.utilization_enc, - utilization_dec=gpu.utilization_dec, - power_draw=gpu.power_draw, - enforced_power_limit=gpu.power_limit, - memory_used=gpu.memory_used, - memory_total=gpu.memory_total, - processes=list(gpu.processes), - ) - for gpu in stats.gpus - ] - - return GpuInfosResponse(data=gpu_infos) +@router.get("/gpus-info", response_model=GpusInfoResponse) +def get_gpus_info() -> GpusInfoResponse: + + gpus_info = system_service.get_gpus_info() + + return GpusInfoResponse(data=gpus_info) diff --git a/app/api/v1/schemas/system.py b/app/api/v1/schemas/system.py index 2a19f4b1..ec8ece03 100644 --- a/app/api/v1/schemas/system.py +++ b/app/api/v1/schemas/system.py @@ -34,5 +34,5 @@ class ServerInfoResponse(ResponseItem): data: ServerInfoPayload -class GpuInfosResponse(ResponseItem): +class GpusInfoResponse(ResponseItem): data: List[GpuInfoPayload] diff --git a/app/services/system.py b/app/services/system.py index 3123b09b..e92b27b0 100644 --- a/app/services/system.py +++ b/app/services/system.py @@ -1,6 +1,8 @@ from typing import List -from app.api.v1.schemas.system import LibraryInfo +from gpustat import GPUStatCollection + +from app.api.v1.schemas.system import GpuInfoPayload, LibraryInfo from netspresso.clients.utils.system import get_package_version @@ -15,5 +17,29 @@ def get_installed_libraries(self) -> List[LibraryInfo]: return installed_libraries + def get_gpus_info(self) -> List[GpuInfoPayload]: + stats = GPUStatCollection.new_query() + + gpus_info = [ + GpuInfoPayload( + index=gpu.index, + uuid=gpu.uuid, + name=gpu.name, + temperature_gpu=gpu.temperature, + fan_speed=gpu.fan_speed, + utilization_gpu=gpu.utilization, + utilization_enc=gpu.utilization_enc, + utilization_dec=gpu.utilization_dec, + power_draw=gpu.power_draw, + enforced_power_limit=gpu.power_limit, + memory_used=gpu.memory_used, + memory_total=gpu.memory_total, + processes=list(gpu.processes), + ) + for gpu in stats.gpus + ] + + return gpus_info + system_service = SystemService()