41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import os
|
|
import psutil
|
|
from modules.base_module import BaseModule
|
|
|
|
class SystemInfoModule(BaseModule):
|
|
|
|
def get_display_text(self):
|
|
lines = []
|
|
|
|
# CPU temperature
|
|
try:
|
|
with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
|
|
temp_str = f.read()
|
|
cpu_temp = round(int(temp_str) / 1000.0, 1)
|
|
lines.append(f"CPU Temp: {cpu_temp}°C")
|
|
except FileNotFoundError:
|
|
lines.append("CPU Temp: N/A")
|
|
|
|
# CPU usage
|
|
cpu_usage = psutil.cpu_percent(interval=0.2)
|
|
lines.append(f"CPU Usage: {cpu_usage}%")
|
|
|
|
# Memory usage
|
|
mem = psutil.virtual_memory()
|
|
mem_used = round(mem.used / (1024 * 1024))
|
|
mem_total = round(mem.total / (1024 * 1024))
|
|
lines.append(f"Mem: {mem_used}/{mem_total}MB")
|
|
|
|
# IP address
|
|
ip_address = "No IP"
|
|
for interface, addrs in psutil.net_if_addrs().items():
|
|
for addr in addrs:
|
|
if addr.family == 2 and not addr.address.startswith("127."):
|
|
ip_address = addr.address
|
|
break
|
|
if ip_address != "No IP":
|
|
break
|
|
lines.append(f"IP: {ip_address}")
|
|
|
|
return "\n".join(lines)
|