From 605622f7db557dd542d05da3601e681a2a4d9f76 Mon Sep 17 00:00:00 2001 From: andersonid Date: Fri, 3 Oct 2025 20:29:04 -0300 Subject: [PATCH] Fix CPU and Memory summary calculation - Change from sum() to current value (last point) for accurate usage - CPU and Memory should show current usage, not sum of all data points - Fixes issue where memory usage was incorrectly showing 800+ MB - Now shows realistic current resource consumption values --- app/services/historical_analysis.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/services/historical_analysis.py b/app/services/historical_analysis.py index ee5e721..3866591 100644 --- a/app/services/historical_analysis.py +++ b/app/services/historical_analysis.py @@ -1475,9 +1475,10 @@ class HistoricalAnalysisService: datetime.utcnow()) if data and len(data) > 0: - # Sum all pod values for the workload - total_cpu = sum(self._safe_float(point[1]) for point in data if point[1] != 'NaN') - return total_cpu + # Get current value (last point) for the workload + # For CPU, we want the current rate, not sum of all points + current_cpu = self._safe_float(data[-1][1]) if data[-1][1] != 'NaN' else 0 + return current_cpu return 0.0 @@ -1514,9 +1515,10 @@ class HistoricalAnalysisService: datetime.utcnow()) if data and len(data) > 0: - # Sum all pod values for the workload - total_memory = sum(self._safe_float(point[1]) for point in data if point[1] != 'NaN') - return total_memory + # Get current value (last point) for the workload + # For memory, we want the current usage, not sum of all points + current_memory = self._safe_float(data[-1][1]) if data[-1][1] != 'NaN' else 0 + return current_memory return 0.0