mirror of
https://github.com/snowykami/server-status-client.git
synced 2024-11-22 15:18:00 +08:00
✨ 新增排序功能
This commit is contained in:
parent
7cbca85a60
commit
b30b3429ad
@ -144,7 +144,8 @@ class Api:
|
|||||||
|
|
||||||
|
|
||||||
class Client:
|
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):
|
interval: int = 2):
|
||||||
self.api = Api(addr, {"token": token, "id": client_id})
|
self.api = Api(addr, {"token": token, "id": client_id})
|
||||||
self.api = self.api.group("/client")
|
self.api = self.api.group("/client")
|
||||||
@ -167,7 +168,6 @@ class Client:
|
|||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.observe()
|
self.observe()
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
resp = self.get_ping()
|
resp = self.get_ping()
|
||||||
@ -205,7 +205,8 @@ class Client:
|
|||||||
"name": self.name,
|
"name": self.name,
|
||||||
"os": {
|
"os": {
|
||||||
"name": platform.system(), # 系统类型 linux|windows|darwin
|
"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
|
"machine": platform.machine(), # 机器类型 x86_64
|
||||||
"release": os_version, # 系统版本
|
"release": os_version, # 系统版本
|
||||||
},
|
},
|
||||||
@ -249,6 +250,7 @@ class Client:
|
|||||||
|
|
||||||
def _observe():
|
def _observe():
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
self.hardware.mem_total = psutil.virtual_memory().total
|
self.hardware.mem_total = psutil.virtual_memory().total
|
||||||
self.hardware.mem_used = psutil.virtual_memory().used
|
self.hardware.mem_used = psutil.virtual_memory().used
|
||||||
self.hardware.swap_total = psutil.swap_memory().total
|
self.hardware.swap_total = psutil.swap_memory().total
|
||||||
@ -274,8 +276,10 @@ class Client:
|
|||||||
self.hardware.cpu_percent = psutil.cpu_percent(1)
|
self.hardware.cpu_percent = psutil.cpu_percent(1)
|
||||||
self.hardware.net_up, self.hardware.net_down = get_network_speed(1)
|
self.hardware.net_up, self.hardware.net_down = get_network_speed(1)
|
||||||
log("Observed")
|
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:
|
def remove(self, client_id) -> requests.Response:
|
||||||
return self.api.delete("/host", data={"id": client_id})
|
return self.api.delete("/host", data={"id": client_id})
|
||||||
|
Loading…
Reference in New Issue
Block a user