WarpWing commited on
Commit
c44fcb7
1 Parent(s): 02af70c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -54,7 +54,10 @@ def get_metrics(token: str = Depends(get_current_token)):
54
  # Memory usage relative to 16GB of RAM
55
  memory = psutil.virtual_memory()
56
  memory_used_gb = (memory.total - memory.available) / (1024 ** 3)
57
- memory_usage_percent = (memory_used_gb / MAX_MEMORY_GB) * 100
 
 
 
58
 
59
  # Disk usage for uploads directory relative to 50GB storage
60
  uploads_size_bytes = get_directory_size(UPLOAD_DIRECTORY)
@@ -64,7 +67,7 @@ def get_metrics(token: str = Depends(get_current_token)):
64
  return {
65
  "cpu_usage_cores": cpu_percent, # Relative CPU usage as cores (out of 2 vCPUs)
66
  "memory": {
67
- "used_gb": round(memory_used_gb, 2),
68
  "used_percent_of_16gb": round(memory_usage_percent, 2)
69
  },
70
  "disk": {
 
54
  # Memory usage relative to 16GB of RAM
55
  memory = psutil.virtual_memory()
56
  memory_used_gb = (memory.total - memory.available) / (1024 ** 3)
57
+
58
+ # Make sure to cap the used memory at MAX_MEMORY_GB
59
+ memory_used_gb_relative = min(memory_used_gb, MAX_MEMORY_GB)
60
+ memory_usage_percent = (memory_used_gb_relative / MAX_MEMORY_GB) * 100
61
 
62
  # Disk usage for uploads directory relative to 50GB storage
63
  uploads_size_bytes = get_directory_size(UPLOAD_DIRECTORY)
 
67
  return {
68
  "cpu_usage_cores": cpu_percent, # Relative CPU usage as cores (out of 2 vCPUs)
69
  "memory": {
70
+ "used_gb": round(memory_used_gb_relative, 2), # Capped at 16GB max
71
  "used_percent_of_16gb": round(memory_usage_percent, 2)
72
  },
73
  "disk": {