Add more CPU details for the host

This commit is contained in:
sqozz 2021-05-06 19:16:41 +02:00
parent fb452da28f
commit 0fa20ed0b4
2 changed files with 24 additions and 3 deletions

View file

@ -33,7 +33,7 @@
<div class="server details">
<textarea name="specs" rows=20 readonly>
Hardware:
• CPU: {{server_details["hardware"]["cpu"]}}
• CPU: {{server_details["hardware"]["cpu"]["cores"]}} Cores with {{server_details["hardware"]["cpu"]["threads"]}} Threads on a {{server_details["hardware"]["cpu"]["name"]}}
• RAM: {{server_details["hardware"]["ram"]}} GB
Versions:

View file

@ -86,11 +86,32 @@ def news():
news = news_file.read()
def hardware_info():
processor = platform.processor()
processor = get_cpuinfo()
mem_bytes = sysconf('SC_PAGE_SIZE') * sysconf('SC_PHYS_PAGES')
mem_gib = mem_bytes/(1024.**3)
mem_pretty = round(mem_gib, 1)
return {"cpu": processor, "ram": mem_pretty}
return {"cpu": {"cores": processor[0]["cpu cores"], "threads": len(processor), "name": processor[0]["model name"]}, "ram": mem_pretty}
def get_cpuinfo():
cpus = []
with open("/proc/cpuinfo", "r") as fp:
cpuinfo = fp.read()
thread_info = cpuinfo.split("\n\n")
thread_info = list(filter(lambda x: x!="", thread_info))
for thread in thread_info:
thread_dict = {}
field_lines = thread.split("\n")
for field in field_lines:
key, value = field.split(":")
key = key.strip()
value = value.strip()
try:
thread_dict.update({key: int(value)})
except ValueError:
thread_dict.update({key: value})
cpus.append(thread_dict)
return cpus
def paper_version():
status = server_status()