diff --git a/panel/admin/index.php b/panel/admin/index.php index 4be53aa..31c96fe 100644 --- a/panel/admin/index.php +++ b/panel/admin/index.php @@ -38,7 +38,10 @@ require_once dirname(__DIR__) . '/_branding.php'; Dashboard - + + + Server Status + - - -
-
24-Hour History${hist.length} samples
-
- ${hist.length === 0 ? '

No history yet — collected every 5 min.

' : ''} -
`; - setTimeout(() => { const canvas = document.getElementById('dash-hist-chart'); if (!canvas || !hist.length) return; if (window.Chart) { initStatsChart(canvas, hist); } else { const sc = document.createElement('script'); sc.src = 'https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js'; sc.onload = () => initStatsChart(canvas, hist); document.head.appendChild(sc); } }, 150); } // ── Server Status ────────────────────────────────────────────────────────── + async function serverStatus() { + const [liveRes, histRes] = await Promise.all([ + Nova.api('system', 'stats'), + Nova.api('stats', 'server'), + ]); + const s = liveRes?.data || {}; + const hist = histRes?.data?.history || []; + + const html = ` + +
+
CPU
${s.cpu?.pct??0}%
${Nova.progressBar(s.cpu?.pct||0)}
+
RAM
${s.ram?.pct??0}%
${Nova.progressBar(s.ram?.pct||0)}
+
Disk
${s.disk?.pct??0}%
${Nova.progressBar(s.disk?.pct||0)}
+
Load Avg
${(s.cpu?.load||[0]).map(v=>v.toFixed(2)).join(' / ')}
Uptime: ${s.uptime||'—'}
+
+
+
24-Hour History${hist.length} samples
+
+ ${hist.length === 0 + ? '

No history yet — stats are collected every 5 minutes.
Check that the collector cron is running: */5 * * * * root /usr/bin/php /opt/novacpx/bin/collect-stats.php

' + : ''} +
+
`; + + // Can't return html and async render chart — use a trick: render then init chart + setTimeout(() => { + const canvas = document.getElementById('stats-chart'); + if (!canvas || !hist.length) return; + if (!window.Chart) { + const s = document.createElement('script'); + s.src = 'https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js'; + s.onload = () => initStatsChart(canvas, hist); + document.head.appendChild(s); + } else { + initStatsChart(canvas, hist); + } + }, 100); + + return html; + } function initStatsChart(canvas, hist) { const labels = hist.map(r => {