/** * Admin > Monitoring > Dashboard */ const { html } = window; const { useState, useEffect, useCallback, useRef } = hooks; export default function DashboardSection() { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const timerRef = useRef(null); const load = useCallback(async () => { try { const d = await sw.api.admin.dashboard(); setData(d); } catch (e) { sw.toast(e.message, 'error'); } finally { setLoading(false); } }, []); useEffect(() => { load(); timerRef.current = setInterval(load, 10000); return () => clearInterval(timerRef.current); }, []); function formatUptime(seconds) { if (!seconds) return '\u2014'; const d = Math.floor(seconds / 86400); const h = Math.floor((seconds % 86400) / 3600); const m = Math.floor((seconds % 3600) / 60); if (d > 0) return `${d}d ${h}h`; if (h > 0) return `${h}h ${m}m`; return `${m}m`; } function formatBytes(b) { if (!b) return '0 B'; if (b < 1048576) return (b / 1024).toFixed(0) + ' KB'; if (b < 1073741824) return (b / 1048576).toFixed(1) + ' MB'; return (b / 1073741824).toFixed(2) + ' GB'; } if (loading) return html`
Auto-refreshes every 10s