Fix: Replace mock data with real Thanos data in Resource Utilization Trend chart
This commit is contained in:
@@ -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
|
||||||
|
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'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 clusterStatus = await fetch('/api/v1/cluster/status').then(r => r.json());
|
||||||
const currentCpuUtil = clusterStatus.summary?.cpu_utilization || 0;
|
const currentCpuUtil = clusterStatus.summary?.cpu_utilization || 0;
|
||||||
const currentMemoryUtil = clusterStatus.summary?.memory_utilization || 0;
|
const currentMemoryUtil = clusterStatus.summary?.memory_utilization || 0;
|
||||||
|
|
||||||
for (let i = 23; i >= 0; i--) {
|
// Create single data point with current values
|
||||||
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));
|
|
||||||
|
|
||||||
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'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user