Spaces:
BG5
/
Running

BG5 commited on
Commit
86108d4
·
verified ·
1 Parent(s): 3959fe2

Update fun.py

Browse files
Files changed (1) hide show
  1. fun.py +16 -4
fun.py CHANGED
@@ -27,12 +27,24 @@ 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 = cpu.split(",")[0].split(":")[-1].strip()
 
 
 
 
 
 
31
  mem_values = mem.split()[1:4]
32
  mem_total, mem_used, mem_free = mem_values
33
- mem = f"Total: {mem_total}MB, Used: {mem_used}MB, Free: {mem_free}MB"
34
- logger.info(f"CPU: {cpu}, Memory: {mem}")
35
- info = {"CPU": {cpu}, "Memory": {mem}}
 
 
 
 
 
 
36
  return info
37
 
38
 
 
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
+ cpu_info[key.strip()] = value.strip() + "%"
36
+ # 解析内存信息
37
  mem_values = mem.split()[1:4]
38
  mem_total, mem_used, mem_free = mem_values
39
+ mem_available = int(mem_total) - int(mem_used)
40
+ mem_info = {
41
+ "Total": f"{mem_total}MB",
42
+ "Used": f"{mem_used}MB",
43
+ "Free": f"{mem_free}MB",
44
+ "Available": f"{mem_available}MB"
45
+ }
46
+ logger.info(f"CPU: {cpu_info}, Memory: {mem_info}")
47
+ info = {"CPU": cpu_info, "Memory": mem_info}
48
  return info
49
 
50