🎉 Improved backend structure & logs organization 🎉
This commit is contained in:
@ -6321,53 +6321,14 @@ def api_admin_stats_live():
|
||||
cpu_percent = psutil.cpu_percent(interval=1)
|
||||
memory_percent = psutil.virtual_memory().percent
|
||||
|
||||
# Windows-sichere Disk-Usage-Bestimmung
|
||||
disk_percent = 0.0
|
||||
try:
|
||||
if os.name == 'nt': # Windows
|
||||
# Windows: Verwende sicheren Pfad-Ansatz
|
||||
import string
|
||||
|
||||
# Versuche verschiedene Windows-Laufwerke
|
||||
drives_to_check = ['C:', 'D:', 'E:']
|
||||
|
||||
for drive in drives_to_check:
|
||||
try:
|
||||
# Prüfe ob Laufwerk existiert
|
||||
if os.path.exists(drive + '\\'):
|
||||
disk_usage = psutil.disk_usage(drive + '\\')
|
||||
disk_percent = disk_usage.percent
|
||||
break
|
||||
except (OSError, SystemError) as drive_error:
|
||||
app_logger.debug(f"Laufwerk {drive} nicht verfügbar: {str(drive_error)}")
|
||||
continue
|
||||
|
||||
# Fallback: Verwende os.statvfs alternative
|
||||
if disk_percent == 0.0:
|
||||
try:
|
||||
import shutil
|
||||
total, used, free = shutil.disk_usage('C:\\')
|
||||
disk_percent = (used / total) * 100.0
|
||||
except Exception as shutil_error:
|
||||
app_logger.debug(f"Shutil disk_usage fehlgeschlagen: {str(shutil_error)}")
|
||||
disk_percent = 0.0
|
||||
|
||||
else: # Unix/Linux
|
||||
# Unix: Standard-Pfad verwenden
|
||||
disk_percent = psutil.disk_usage('/').percent
|
||||
|
||||
except Exception as disk_error:
|
||||
app_logger.warning(f"Disk-Usage-Bestimmung fehlgeschlagen: {str(disk_error)}")
|
||||
disk_percent = 0.0
|
||||
# Disk-Pfad sicher bestimmen
|
||||
disk_path = '/' if os.name != 'nt' else 'C:\\'
|
||||
disk_percent = psutil.disk_usage(disk_path).percent
|
||||
|
||||
# Uptime sicher berechnen
|
||||
try:
|
||||
boot_time = psutil.boot_time()
|
||||
current_time = time.time()
|
||||
uptime_seconds = int(current_time - boot_time)
|
||||
except Exception as uptime_error:
|
||||
app_logger.debug(f"Uptime-Berechnung fehlgeschlagen: {str(uptime_error)}")
|
||||
uptime_seconds = 0
|
||||
boot_time = psutil.boot_time()
|
||||
current_time = time.time()
|
||||
uptime_seconds = int(current_time - boot_time)
|
||||
|
||||
stats['system'] = {
|
||||
'cpu_percent': float(cpu_percent),
|
||||
@ -6741,4 +6702,4 @@ if __name__ == "__main__":
|
||||
stop_queue_manager()
|
||||
except:
|
||||
pass
|
||||
sys.exit(1)
|
||||
sys.exit(1)
|
Reference in New Issue
Block a user