feat: 缓存列表,监控,性能监控添加按钮级权限控制
This commit is contained in:
@@ -14,12 +14,14 @@ import psutil
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
from annotation.auth import Auth
|
||||
from annotation.log import Log
|
||||
from config.constant import BusinessType
|
||||
from controller.login import LoginController
|
||||
from schemas.server import GetServerInfoResponse, CpuInfo, MemoryInfo, SystemInfo, PythonInfo, SystemFiles, \
|
||||
GetSystemInfoResult
|
||||
from utils.common import bytes2human
|
||||
from utils.log import logger
|
||||
from utils.response import Response
|
||||
|
||||
serverAPI = APIRouter(
|
||||
@@ -30,6 +32,7 @@ serverAPI = APIRouter(
|
||||
|
||||
@serverAPI.get("", response_class=JSONResponse, response_model=GetServerInfoResponse, summary="获取服务器信息")
|
||||
@Log(title="获取服务器信息", business_type=BusinessType.SELECT)
|
||||
@Auth(permission_list=["server:btn:info"])
|
||||
async def get_server_info(request: Request):
|
||||
# CPU信息
|
||||
# 获取CPU总核心数
|
||||
@@ -96,17 +99,21 @@ async def get_server_info(request: Request):
|
||||
io = psutil.disk_partitions()
|
||||
sys_files = []
|
||||
for i in io:
|
||||
o = psutil.disk_usage(i.device)
|
||||
disk_data = SystemFiles(
|
||||
dirName=i.device,
|
||||
sysTypeName=i.fstype,
|
||||
typeName='本地固定磁盘(' + i.mountpoint.replace('\\', '') + ')',
|
||||
total=bytes2human(o.total),
|
||||
used=bytes2human(o.used),
|
||||
free=bytes2human(o.free),
|
||||
usage=f'{psutil.disk_usage(i.device).percent}%',
|
||||
)
|
||||
sys_files.append(disk_data)
|
||||
try:
|
||||
o = psutil.disk_usage(i.device)
|
||||
disk_data = SystemFiles(
|
||||
dirName=i.device,
|
||||
sysTypeName=i.fstype,
|
||||
typeName='本地固定磁盘(' + i.mountpoint.replace('\\', '') + ')',
|
||||
total=bytes2human(o.total),
|
||||
used=bytes2human(o.used),
|
||||
free=bytes2human(o.free),
|
||||
usage=f'{psutil.disk_usage(i.device).percent}%',
|
||||
)
|
||||
sys_files.append(disk_data)
|
||||
except Exception as e:
|
||||
logger.error(f"获取磁盘信息失败:{e}")
|
||||
continue
|
||||
|
||||
result = GetSystemInfoResult(cpu=cpu, memory=mem, system=sys, python=py, systemFiles=sys_files)
|
||||
return Response.success(data=result)
|
||||
|
||||
Reference in New Issue
Block a user