From f00d88c4419fdafdb5232f29a86e9b9701e51a1a Mon Sep 17 00:00:00 2001 From: andersonid Date: Mon, 27 Oct 2025 14:17:37 -0300 Subject: [PATCH] Fix: Replace mock data with real Thanos data in Resource Utilization Trend chart --- app/static/index.html | 59 +++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 19 deletions(-) diff --git a/app/static/index.html b/app/static/index.html index 836607a..b8728a9 100644 --- a/app/static/index.html +++ b/app/static/index.html @@ -3736,8 +3736,8 @@ // Update progress updateSmartProgress(2, 'Loading resource utilization trend...'); - // Use real Prometheus data from historical analysis - const response = await fetch('/api/v1/optimized/historical/summary'); + // Fetch real data from Thanos API for last 24 hours + const response = await fetch('/api/v1/hybrid/resource-trends?days=1'); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } @@ -3747,29 +3747,50 @@ const trendData = []; const now = new Date(); - // Generate 24h trend based on current cluster status - const clusterStatus = await fetch('/api/v1/cluster/status').then(r => r.json()); - const currentCpuUtil = clusterStatus.summary?.cpu_utilization || 0; - const currentMemoryUtil = clusterStatus.summary?.memory_utilization || 0; + // Process real Thanos data + if (data.trends && data.trends.cpu_trend && data.trends.cpu_trend.data && data.trends.cpu_trend.data.result) { + const cpuResult = data.trends.cpu_trend.data.result[0]; + const memoryResult = data.trends.memory_trend.data.result[0]; + + if (cpuResult && cpuResult.values && memoryResult && memoryResult.values) { + const cpuValues = cpuResult.values; + const memoryValues = memoryResult.values; + const length = Math.min(cpuValues.length, memoryValues.length); + + for (let i = 0; i < length; i++) { + const timestamp = parseInt(cpuValues[i][0]) * 1000; // Convert to JS timestamp + const cpuValue = parseFloat(cpuValues[i][1]) || 0; + const memoryValue = parseFloat(memoryValues[i][1]) || 0; + + trendData.push({ + x: timestamp, + y: cpuValue * 100, // Convert to percentage + type: 'CPU' + }); + trendData.push({ + x: timestamp, + y: memoryValue / 1024 / 1024 / 1024, // Convert bytes to GB + type: 'Memory' + }); + } + } + } - for (let i = 23; i >= 0; i--) { - const time = new Date(now.getTime() - (i * 60 * 60 * 1000)); - - // Simulate realistic variation around current utilization - const cpuVariation = (Math.random() - 0.5) * 20; // ±10% variation - const memoryVariation = (Math.random() - 0.5) * 20; - - const cpuUtil = Math.max(0, Math.min(100, currentCpuUtil + cpuVariation)); - const memoryUtil = Math.max(0, Math.min(100, currentMemoryUtil + memoryVariation)); + // If no real data from Thanos, use current cluster status as fallback + if (trendData.length === 0) { + const clusterStatus = await fetch('/api/v1/cluster/status').then(r => r.json()); + const currentCpuUtil = clusterStatus.summary?.cpu_utilization || 0; + const currentMemoryUtil = clusterStatus.summary?.memory_utilization || 0; + // Create single data point with current values trendData.push({ - x: time.getTime(), - y: cpuUtil, + x: now.getTime(), + y: currentCpuUtil, type: 'CPU' }); trendData.push({ - x: time.getTime(), - y: memoryUtil, + x: now.getTime(), + y: currentMemoryUtil, type: 'Memory' }); }