Skip to content

Commit

Permalink
#415 Add API for retrieving server information (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
Only-bottle authored Dec 5, 2024
1 parent dbb9a21 commit 9d904b0
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 31 deletions.
40 changes: 10 additions & 30 deletions app/api/v1/endpoints/system.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,27 @@
from fastapi import APIRouter
from gpustat import GPUStatCollection

from app.api.v1.schemas.system import (
GpuInfoPayload,
GpuInfosResponse,
LibraryInfo,
GpusInfoResponse,
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)


@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)
2 changes: 1 addition & 1 deletion app/api/v1/schemas/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ class ServerInfoResponse(ResponseItem):
data: ServerInfoPayload


class GpuInfosResponse(ResponseItem):
class GpusInfoResponse(ResponseItem):
data: List[GpuInfoPayload]
Empty file added app/services/__init__.py
Empty file.
45 changes: 45 additions & 0 deletions app/services/system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from typing import List

from gpustat import GPUStatCollection

from app.api.v1.schemas.system import GpuInfoPayload, 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

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()

0 comments on commit 9d904b0

Please sign in to comment.