新增排序功能
Some checks failed
Compile / build (x64, ubuntu-latest) (push) Failing after 1m27s
Compile / build (x64, windows-latest) (push) Has been cancelled

This commit is contained in:
远野千束 2024-10-11 01:15:39 +08:00
parent 7cbca85a60
commit b30b3429ad

View File

@ -144,7 +144,8 @@ class Api:
class Client:
def __init__(self, addr: str, token: str, client_id: str, name: str = "", location: str = "", labels: list[str] = [], link: str = "",
def __init__(self, addr: str, token: str, client_id: str, name: str = "", location: str = "",
labels: list[str] = [], link: str = "",
interval: int = 2):
self.api = Api(addr, {"token": token, "id": client_id})
self.api = self.api.group("/client")
@ -167,7 +168,6 @@ class Client:
def start(self):
self.observe()
while True:
try:
resp = self.get_ping()
@ -205,7 +205,8 @@ class Client:
"name": self.name,
"os": {
"name": platform.system(), # 系统类型 linux|windows|darwin
"version": os_name + os_version, # 系统版本复杂描述 #1 SMP PREEMPT_DYNAMIC Fri Sep 13 10:42:50 UTC 2024 (5c05eeb)
"version": os_name + os_version,
# 系统版本复杂描述 #1 SMP PREEMPT_DYNAMIC Fri Sep 13 10:42:50 UTC 2024 (5c05eeb)
"machine": platform.machine(), # 机器类型 x86_64
"release": os_version, # 系统版本
},
@ -249,6 +250,7 @@ class Client:
def _observe():
while True:
try:
self.hardware.mem_total = psutil.virtual_memory().total
self.hardware.mem_used = psutil.virtual_memory().used
self.hardware.swap_total = psutil.swap_memory().total
@ -274,8 +276,10 @@ class Client:
self.hardware.cpu_percent = psutil.cpu_percent(1)
self.hardware.net_up, self.hardware.net_down = get_network_speed(1)
log("Observed")
except Exception as e:
log(f"Failed to observe: {e}")
threading.Thread(target=_observe, daemon=True).start()
threading.Thread(target=_observe).start()
def remove(self, client_id) -> requests.Response:
return self.api.delete("/host", data={"id": client_id})