40 lines
919 B
Plaintext
40 lines
919 B
Plaintext
// components/chart.js
|
|
const ctx = document.getElementById('mainChart').getContext('2d');
|
|
let chart;
|
|
|
|
export async function updateChart() {
|
|
const res = await fetch('/api/metrics');
|
|
const data = await res.json();
|
|
|
|
if (chart) chart.destroy();
|
|
|
|
chart = new Chart(ctx, {
|
|
type: 'line',
|
|
data: {
|
|
labels: data.timeline,
|
|
datasets: [
|
|
{
|
|
label: 'Utilisation CPU',
|
|
data: data.cpu,
|
|
borderColor: '#FF6B6B',
|
|
tension: 0.1
|
|
},
|
|
{
|
|
label: 'Mémoire (GB)',
|
|
data: data.memory,
|
|
borderColor: '#4ECDC4',
|
|
tension: 0.1
|
|
}
|
|
]
|
|
},
|
|
options: { responsive: true, maintainAspectRatio: false }
|
|
});
|
|
|
|
document.getElementById('metrics').innerHTML = `
|
|
<p>Dernière mise à jour : ${new Date().toLocaleTimeString()}</p>
|
|
`;
|
|
}
|
|
|
|
// Rafraîchissement auto
|
|
setInterval(updateChart, 30000);
|
|
updateChart(); |