Update fun.py
Browse files
fun.py
CHANGED
@@ -27,12 +27,25 @@ PROFILE_BASE = "/tmp/profiles"
|
|
27 |
def get_system_usage():
|
28 |
cpu = subprocess.check_output("top -bn1 | grep 'Cpu(s)'", shell=True).decode().strip()
|
29 |
mem = subprocess.check_output("free -m | grep Mem", shell=True).decode().strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
# 解析CPU信息
|
31 |
cpu_parts = cpu.split(":")[1].split(",")
|
32 |
cpu_info = {}
|
33 |
for part in cpu_parts:
|
34 |
value, key = part.strip().split(" ", 1)
|
35 |
-
|
|
|
|
|
36 |
# 解析内存信息
|
37 |
mem_values = mem.split()[1:4]
|
38 |
mem_total, mem_used, mem_free = mem_values
|
@@ -349,4 +362,4 @@ async def cdp_native_ws_proxy(websocket: WebSocket, tab_type: str, target_id: st
|
|
349 |
|
350 |
|
351 |
if __name__ == "__main__":
|
352 |
-
uvicorn.run("
|
|
|
27 |
def get_system_usage():
|
28 |
cpu = subprocess.check_output("top -bn1 | grep 'Cpu(s)'", shell=True).decode().strip()
|
29 |
mem = subprocess.check_output("free -m | grep Mem", shell=True).decode().strip()
|
30 |
+
# 字段映射
|
31 |
+
cpu_key_map = {
|
32 |
+
"us": "user",
|
33 |
+
"sy": "system",
|
34 |
+
"ni": "nice",
|
35 |
+
"id": "idle",
|
36 |
+
"wa": "iowait",
|
37 |
+
"hi": "hardware_irq",
|
38 |
+
"si": "software_irq",
|
39 |
+
"st": "steal"
|
40 |
+
}
|
41 |
# 解析CPU信息
|
42 |
cpu_parts = cpu.split(":")[1].split(",")
|
43 |
cpu_info = {}
|
44 |
for part in cpu_parts:
|
45 |
value, key = part.strip().split(" ", 1)
|
46 |
+
key = key.strip().replace("%", "")
|
47 |
+
mapped_key = cpu_key_map.get(key, key)
|
48 |
+
cpu_info[mapped_key] = value.strip() + "%"
|
49 |
# 解析内存信息
|
50 |
mem_values = mem.split()[1:4]
|
51 |
mem_total, mem_used, mem_free = mem_values
|
|
|
362 |
|
363 |
|
364 |
if __name__ == "__main__":
|
365 |
+
uvicorn.run("api:app", host="0.0.0.0", port=8000, reload=True)
|