Fix: Replace mock data with real Thanos data in Resource Utilization Trend chart
This commit is contained in:
@@ -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];
|
||||
|
||||
for (let i = 23; i >= 0; i--) {
|
||||
const time = new Date(now.getTime() - (i * 60 * 60 * 1000));
|
||||
if (cpuResult && cpuResult.values && memoryResult && memoryResult.values) {
|
||||
const cpuValues = cpuResult.values;
|
||||
const memoryValues = memoryResult.values;
|
||||
const length = Math.min(cpuValues.length, memoryValues.length);
|
||||
|
||||
// Simulate realistic variation around current utilization
|
||||
const cpuVariation = (Math.random() - 0.5) * 20; // ±10% variation
|
||||
const memoryVariation = (Math.random() - 0.5) * 20;
|
||||
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;
|
||||
|
||||
const cpuUtil = Math.max(0, Math.min(100, currentCpuUtil + cpuVariation));
|
||||
const memoryUtil = Math.max(0, Math.min(100, currentMemoryUtil + memoryVariation));
|
||||
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'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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'
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user