BE+FE: System info -> Performance section

This commit is contained in:
jokob-sk committed 2026-09-28 14:40:11 +10:00
1 parent 491b60b49e
commit 4aa2a0dddb
51 files changed
+1548 -97

No files matched your search

+1 -1
View File
@@ -2058,7 +2058,7 @@ def check_auth(payload=None):
@validate_request(
operation_id="check_health",
summary="System Health Check",
description="Retrieve system vitality metrics including database size, memory pressure, system load, disk usage, and CPU temperature.",
description="Retrieve system vitality metrics including database size, memory pressure, system load, disk usage, CPU temperature, and the NetAlertX process's own CPU%/RSS.",
response_model=HealthCheckResponse,
tags=["system", "health"],
auth_callable=is_authorized
+44
View File
@@ -155,6 +155,48 @@ def get_storage_gb():
return None
# ===============================================================================
# Process Vitality (NetAlertX's own process, not the host)
# ===============================================================================
# Non-blocking cpu_percent() needs one persistent Process object to mean anything
# ("since the last time this was called") - this object is dedicated to /health only,
# never shared with the tick-scoped sampler in scan/resource_history.py, so the two
# measurement paths can't interfere with each other.
_health_process = psutil.Process()
def get_process_cpu_percent():
"""
CPU% for the NetAlertX process since the last time this was called - a live
gauge for /health, not a tick-scoped measurement (see scan/resource_history.py's
tick-scoped sampler for that).
Returns:
float: CPU utilization percentage, or 0.0 on error.
"""
try:
return _health_process.cpu_percent(interval=None)
except (psutil.Error, AttributeError) as e:
mylog("verbose", [f"[health] Error reading process CPU%: {e}"])
return 0.0
def get_process_rss_mb():
"""
Resident memory (RSS) for the current process, in MB - a point-in-time
snapshot, not a delta (RSS doesn't accumulate the way CPU-time/IO do).
Returns:
float: RSS in MB, or 0.0 on error.
"""
try:
return round(psutil.Process().memory_info().rss / (1024 * 1024), 2)
except (psutil.Error, AttributeError) as e:
mylog("verbose", [f"[health] Error reading process RSS: {e}"])
return 0.0
# ===============================================================================
# Aggregator
# ===============================================================================
@@ -174,4 +216,6 @@ def get_health_status():
"cpu_temp": get_cpu_temp(),
"storage_gb": get_storage_gb(),
"mem_mb": get_mem_mb(),
"process_cpu_pct": get_process_cpu_percent(),
"process_rss_mb": get_process_rss_mb(),
}
+5 -1
View File
@@ -718,7 +718,9 @@ class HealthCheckResponse(BaseResponse):
"storage_pct": 42,
"cpu_temp": 58,
"storage_gb": 8,
"mem_mb" : 8192
"mem_mb" : 8192,
"process_cpu_pct": 3.2,
"process_rss_mb": 142.75
}]
}
)
@@ -730,6 +732,8 @@ class HealthCheckResponse(BaseResponse):
cpu_temp: Optional[int] = Field(None, description="CPU temperature in Celsius (nullable if unavailable)")
storage_gb: Optional[int] = Field(..., description="Storage size in GB")
mem_mb: Optional[int] = Field(..., description="Installed memory size in MB")
process_cpu_pct: float = Field(..., description="NetAlertX process CPU usage percentage since the last /health call (live gauge, not a tick average)")
process_rss_mb: float = Field(..., description="NetAlertX process resident memory (RSS) in MB")
# =============================================================================