Fix: Replace mock data with real Thanos data in Resource Utilization Trend chart

This commit is contained in:
2025-10-27 14:17:37 -03:00
parent 5a7be90581
commit f00d88c441

View File

@@ -3736,8 +3736,8 @@
// Update progress // Update progress
updateSmartProgress(2, 'Loading resource utilization trend...'); updateSmartProgress(2, 'Loading resource utilization trend...');
// Use real Prometheus data from historical analysis // Fetch real data from Thanos API for last 24 hours
const response = await fetch('/api/v1/optimized/historical/summary'); const response = await fetch('/api/v1/hybrid/resource-trends?days=1');
if (!response.ok) { if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`); throw new Error(`HTTP error! status: ${response.status}`);
} }
@@ -3747,29 +3747,50 @@
const trendData = []; const trendData = [];
const now = new Date(); const now = new Date();
// Generate 24h trend based on current cluster status // Process real Thanos data
const clusterStatus = await fetch('/api/v1/cluster/status').then(r => r.json()); if (data.trends && data.trends.cpu_trend && data.trends.cpu_trend.data && data.trends.cpu_trend.data.result) {
const currentCpuUtil = clusterStatus.summary?.cpu_utilization || 0; const cpuResult = data.trends.cpu_trend.data.result[0];
const currentMemoryUtil = clusterStatus.summary?.memory_utilization || 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--) { // If no real data from Thanos, use current cluster status as fallback
const time = new Date(now.getTime() - (i * 60 * 60 * 1000)); if (trendData.length === 0) {
const clusterStatus = await fetch('/api/v1/cluster/status').then(r => r.json());
// Simulate realistic variation around current utilization const currentCpuUtil = clusterStatus.summary?.cpu_utilization || 0;
const cpuVariation = (Math.random() - 0.5) * 20; // ±10% variation const currentMemoryUtil = clusterStatus.summary?.memory_utilization || 0;
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));
// Create single data point with current values
trendData.push({ trendData.push({
x: time.getTime(), x: now.getTime(),
y: cpuUtil, y: currentCpuUtil,
type: 'CPU' type: 'CPU'
}); });
trendData.push({ trendData.push({
x: time.getTime(), x: now.getTime(),
y: memoryUtil, y: currentMemoryUtil,
type: 'Memory' type: 'Memory'
}); });
} }