Neue GUI
This commit is contained in:
+1074
-176
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
import http.server
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import socketserver
|
||||
import subprocess
|
||||
@@ -30,6 +31,47 @@ def read_cpu_temperature():
|
||||
return 'unbekannt'
|
||||
|
||||
|
||||
def read_cpu_usage():
|
||||
try:
|
||||
with open('/proc/stat', 'r', encoding='utf-8') as handle:
|
||||
first = handle.readline().split()[1:]
|
||||
first = [int(value) for value in first]
|
||||
idle_first = first[3] + first[4]
|
||||
total_first = sum(first)
|
||||
time.sleep(0.12)
|
||||
with open('/proc/stat', 'r', encoding='utf-8') as handle:
|
||||
second = handle.readline().split()[1:]
|
||||
second = [int(value) for value in second]
|
||||
idle_second = second[3] + second[4]
|
||||
total_second = sum(second)
|
||||
total_delta = total_second - total_first
|
||||
idle_delta = idle_second - idle_first
|
||||
if total_delta <= 0:
|
||||
return 'unbekannt'
|
||||
usage = (1 - (idle_delta / total_delta)) * 100
|
||||
return f'{usage:.0f}%'
|
||||
except (FileNotFoundError, ValueError, IndexError):
|
||||
return 'unbekannt'
|
||||
|
||||
|
||||
def read_memory_usage():
|
||||
try:
|
||||
values = {}
|
||||
with open('/proc/meminfo', 'r', encoding='utf-8') as handle:
|
||||
for line in handle:
|
||||
key, raw_value = line.split(':', 1)
|
||||
values[key] = int(raw_value.strip().split()[0])
|
||||
total = values.get('MemTotal')
|
||||
available = values.get('MemAvailable')
|
||||
if not total or available is None:
|
||||
return 'unbekannt'
|
||||
used = total - available
|
||||
percent = (used / total) * 100
|
||||
return f'{percent:.0f}%'
|
||||
except (FileNotFoundError, ValueError):
|
||||
return 'unbekannt'
|
||||
|
||||
|
||||
def format_uptime():
|
||||
try:
|
||||
with open('/proc/uptime', 'r', encoding='utf-8') as handle:
|
||||
@@ -113,6 +155,8 @@ def collect_status():
|
||||
'wifi': get_wifi_status(),
|
||||
'ips': get_ip_addresses(),
|
||||
'cpu_temperature': read_cpu_temperature(),
|
||||
'cpu_usage': read_cpu_usage(),
|
||||
'memory_usage': read_memory_usage(),
|
||||
'uptime': format_uptime(),
|
||||
'disk_free': format_disk_free(),
|
||||
},
|
||||
|
||||
@@ -22,7 +22,7 @@ CONTROLLER_FUNCTION_MAPS = {
|
||||
"webgui": {
|
||||
"x_axis": 0,
|
||||
"y_axis": 1,
|
||||
"invert_x_axis": False,
|
||||
"invert_x_axis": True,
|
||||
"X_button": 0,
|
||||
"Y_button": 3,
|
||||
"A_button": 1,
|
||||
|
||||
Reference in New Issue
Block a user