mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-08 17:08:35 +08:00
add 网络流量API
This commit is contained in:
@@ -166,3 +166,19 @@ def memory2(_: Annotated[str, Depends(verify_apitoken)]) -> Any:
|
|||||||
获取当前内存使用率 API_TOKEN认证(?token=xxx)
|
获取当前内存使用率 API_TOKEN认证(?token=xxx)
|
||||||
"""
|
"""
|
||||||
return memory()
|
return memory()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/network", summary="获取当前网络流量", response_model=List[int])
|
||||||
|
def network(_: schemas.TokenPayload = Depends(verify_token)) -> Any:
|
||||||
|
"""
|
||||||
|
获取当前网络流量(上行和下行流量,单位:bytes/s)
|
||||||
|
"""
|
||||||
|
return SystemUtils.network_usage()
|
||||||
|
|
||||||
|
|
||||||
|
@router.get("/network2", summary="获取当前网络流量(API_TOKEN)", response_model=List[int])
|
||||||
|
def network2(_: Annotated[str, Depends(verify_apitoken)]) -> Any:
|
||||||
|
"""
|
||||||
|
获取当前网络流量 API_TOKEN认证(?token=xxx)
|
||||||
|
"""
|
||||||
|
return network()
|
||||||
|
|||||||
@@ -445,6 +445,24 @@ class SystemUtils:
|
|||||||
process_memory_percent = (process_memory / system_memory) * 100
|
process_memory_percent = (process_memory / system_memory) * 100
|
||||||
return [process_memory, int(process_memory_percent)]
|
return [process_memory, int(process_memory_percent)]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def network_usage() -> List[int]:
|
||||||
|
"""
|
||||||
|
获取当前网络流量(上行和下行流量,单位:bytes/s)
|
||||||
|
"""
|
||||||
|
import time
|
||||||
|
# 获取初始网络统计
|
||||||
|
net_io_1 = psutil.net_io_counters()
|
||||||
|
time.sleep(1) # 等待1秒
|
||||||
|
# 获取1秒后的网络统计
|
||||||
|
net_io_2 = psutil.net_io_counters()
|
||||||
|
|
||||||
|
# 计算1秒内的流量变化
|
||||||
|
upload_speed = net_io_2.bytes_sent - net_io_1.bytes_sent
|
||||||
|
download_speed = net_io_2.bytes_recv - net_io_1.bytes_recv
|
||||||
|
|
||||||
|
return [upload_speed, download_speed]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_hardlink(src: Path, dest: Path) -> bool:
|
def is_hardlink(src: Path, dest: Path) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user