mirror of
https://github.com/snowykami/server-status-client.git
synced 2024-11-22 07:07:58 +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,33 +250,36 @@ class Client:
|
|||||||
|
|
||||||
def _observe():
|
def _observe():
|
||||||
while True:
|
while True:
|
||||||
self.hardware.mem_total = psutil.virtual_memory().total
|
try:
|
||||||
self.hardware.mem_used = psutil.virtual_memory().used
|
self.hardware.mem_total = psutil.virtual_memory().total
|
||||||
self.hardware.swap_total = psutil.swap_memory().total
|
self.hardware.mem_used = psutil.virtual_memory().used
|
||||||
self.hardware.swap_used = psutil.swap_memory().used
|
self.hardware.swap_total = psutil.swap_memory().total
|
||||||
self.hardware.cpu_cores = psutil.cpu_count(logical=False)
|
self.hardware.swap_used = psutil.swap_memory().used
|
||||||
self.hardware.cpu_logics = psutil.cpu_count(logical=True)
|
self.hardware.cpu_cores = psutil.cpu_count(logical=False)
|
||||||
for part in psutil.disk_partitions():
|
self.hardware.cpu_logics = psutil.cpu_count(logical=True)
|
||||||
try:
|
for part in psutil.disk_partitions():
|
||||||
usage = psutil.disk_usage(part.mountpoint)
|
try:
|
||||||
|
usage = psutil.disk_usage(part.mountpoint)
|
||||||
|
|
||||||
if part.mountpoint.startswith(excluded_partition_prefix) or usage.total == 0:
|
if part.mountpoint.startswith(excluded_partition_prefix) or usage.total == 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.hardware.disks[part.device] = {
|
self.hardware.disks[part.device] = {
|
||||||
"mountpoint": part.mountpoint,
|
"mountpoint": part.mountpoint,
|
||||||
"device": part.device,
|
"device": part.device,
|
||||||
"fstype": part.fstype,
|
"fstype": part.fstype,
|
||||||
"total": usage.total,
|
"total": usage.total,
|
||||||
"used": usage.used,
|
"used": usage.used,
|
||||||
}
|
}
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
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