mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-02-20 08:08:05 -05:00
fix: update health check response and schema to handle nullable memory and storage usage
This commit is contained in:
@@ -1955,7 +1955,7 @@ def check_health(payload=None):
|
||||
return jsonify({
|
||||
"success": False,
|
||||
"error": "Failed to retrieve health status",
|
||||
"message": str(e)
|
||||
"message": "Internal server error"
|
||||
}), 500
|
||||
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ def get_mem_usage_pct():
|
||||
Calculate memory usage percentage (used / total * 100).
|
||||
|
||||
Returns:
|
||||
int: Memory usage as integer percentage (0-100), or -1 on error.
|
||||
int: Memory usage as integer percentage (0-100), or None on error.
|
||||
"""
|
||||
try:
|
||||
vm = psutil.virtual_memory()
|
||||
@@ -52,12 +52,7 @@ def get_mem_usage_pct():
|
||||
return max(0, min(100, pct)) # Clamp to 0-100
|
||||
except Exception as e:
|
||||
mylog("verbose", [f"[health] Error calculating memory usage: {e}"])
|
||||
return -1
|
||||
|
||||
|
||||
# ===============================================================================
|
||||
# System Stress
|
||||
# ===============================================================================
|
||||
return None
|
||||
|
||||
def get_load_avg_1m():
|
||||
"""
|
||||
@@ -83,7 +78,7 @@ def get_storage_pct():
|
||||
Calculate disk usage percentage of /data mount.
|
||||
|
||||
Returns:
|
||||
int: Disk usage as integer percentage (0-100), or -1 on error.
|
||||
int: Disk usage as integer percentage (0-100), or None on error.
|
||||
"""
|
||||
try:
|
||||
stat = os.statvfs(dataPath)
|
||||
@@ -93,12 +88,7 @@ def get_storage_pct():
|
||||
return max(0, min(100, pct)) # Clamp to 0-100
|
||||
except Exception as e:
|
||||
mylog("verbose", [f"[health] Error calculating storage usage: {e}"])
|
||||
return -1
|
||||
|
||||
|
||||
# ===============================================================================
|
||||
# Thermal Health
|
||||
# ===============================================================================
|
||||
return None
|
||||
|
||||
def get_cpu_temp():
|
||||
"""
|
||||
|
||||
@@ -673,9 +673,9 @@ class HealthCheckResponse(BaseResponse):
|
||||
)
|
||||
|
||||
db_size_mb: float = Field(..., description="Database size in MB (app.db + app.db-wal)")
|
||||
mem_usage_pct: int = Field(..., ge=0, le=100, description="Memory usage percentage (0-100)")
|
||||
mem_usage_pct: Optional[int] = Field(None, ge=0, le=100, description="Memory usage percentage (0-100, nullable if unavailable)")
|
||||
load_1m: float = Field(..., description="1-minute load average")
|
||||
storage_pct: int = Field(..., ge=0, le=100, description="Disk usage percentage of /data mount (0-100)")
|
||||
storage_pct: Optional[int] = Field(None, ge=0, le=100, description="Disk usage percentage of /data mount (0-100, nullable if unavailable)")
|
||||
cpu_temp: Optional[int] = Field(None, description="CPU temperature in Celsius (nullable if unavailable)")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user