Files
Wu Clan a22aaa0a3e Attempt to optimize serialization performance (#266)
* Attempt to serialize performance optimization

* Add casbin service functions return type

* update comments
2024-01-11 20:15:03 +08:00

32 lines
1.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from fastapi import APIRouter, Depends
from starlette.concurrency import run_in_threadpool
from backend.app.common.jwt import DependsJwtAuth
from backend.app.common.permission import RequestPermission
from backend.app.common.response.response_schema import ResponseModel, response_base
from backend.app.utils.server_info import server_info
router = APIRouter()
@router.get(
'/server',
summary='server 监控',
dependencies=[
Depends(RequestPermission('sys:monitor:server')),
DependsJwtAuth,
],
)
async def get_server_info() -> ResponseModel:
"""IO密集型任务使用线程池尽量减少性能损耗"""
data = {
'cpu': await run_in_threadpool(server_info.get_cpu_info),
'mem': await run_in_threadpool(server_info.get_mem_info),
'sys': await run_in_threadpool(server_info.get_sys_info),
'disk': await run_in_threadpool(server_info.get_disk_info),
'service': await run_in_threadpool(server_info.get_service_info),
}
return await response_base.success(data=data)