149 lines
7.1 KiB
HTML
149 lines
7.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr"><head>
|
|
<meta charset="UTF-8">
|
|
<title>Database Dashboard · Live</title>
|
|
<style>
|
|
body{font-family:-apple-system,BlinkMacSystemFont,sans-serif;background:#0a0e27;color:#e4e8f7;margin:0;padding:24px;min-height:100vh}
|
|
h1{color:#6ba3ff;border-bottom:2px solid #1e3a8a;padding-bottom:8px}
|
|
h2{color:#c084fc;margin-top:32px}
|
|
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:16px;margin:16px 0}
|
|
.card{background:#141933;border:1px solid #263161;border-radius:8px;padding:18px}
|
|
.big{font-size:32px;font-weight:bold;color:#6ba3ff}
|
|
.sub{color:#9ca8d3;font-size:12px;margin-top:4px}
|
|
table{width:100%;border-collapse:collapse;margin:12px 0}
|
|
th,td{padding:8px 12px;border-bottom:1px solid #263161;text-align:left;font-size:13px}
|
|
th{background:#1e2549;color:#9ca8d3;font-size:11px;text-transform:uppercase;letter-spacing:0.5px}
|
|
.badge{display:inline-block;padding:2px 8px;border-radius:4px;font-size:10px;font-weight:bold;text-transform:uppercase}
|
|
.active{background:#10b981;color:#fff}
|
|
.empty{background:#ef4444;color:#fff}
|
|
.warn{background:#f59e0b;color:#fff}
|
|
.info{background:#3b82f6;color:#fff}
|
|
.num{font-family:'SF Mono',Monaco,monospace;color:#6ba3ff;text-align:right}
|
|
#toast{position:fixed;bottom:24px;right:24px;padding:16px 24px;background:#ef4444;color:#fff;border-radius:8px;display:none;z-index:1000;box-shadow:0 8px 24px rgba(0,0,0,0.3)}
|
|
.toast-ok{background:#10b981!important}
|
|
.skeleton{display:inline-block;width:80px;height:28px;background:linear-gradient(90deg,#263161 0%,#1e2549 50%,#263161 100%);background-size:200% 100%;animation:skel 1.5s infinite;border-radius:4px}
|
|
@keyframes skel{0%{background-position:200% 0}100%{background-position:-200% 0}}
|
|
.refresh{color:#9ca8d3;font-size:11px;margin-top:24px;text-align:right}
|
|
.bar-container{width:100%;height:8px;background:#1e2549;border-radius:4px;overflow:hidden;margin-top:6px}
|
|
.bar{height:100%;background:linear-gradient(90deg,#6ba3ff 0%,#c084fc 100%);transition:width 0.3s}
|
|
.search-box{padding:12px;background:#141933;border:1px solid #263161;border-radius:6px;color:#e4e8f7;width:100%;max-width:400px;font-size:14px}
|
|
</style></head>
|
|
<body>
|
|
<h1>🗄️ Database Dashboard · Live</h1>
|
|
<p style="color:#9ca8d3">Live data from PostgreSQL admin/ethica/weval schemas · Auto-refresh 30s · 0 hardcode</p>
|
|
|
|
<h2>Overview</h2>
|
|
<div class="grid">
|
|
<div class="card"><h3>Total tables</h3><div class="big" id="total-tables"><span class="skeleton"></span></div><div class="sub" id="total-tables-sub">Initialisation...</div></div>
|
|
<div class="card"><h3>Active (non-empty)</h3><div class="big" id="active-tables"><span class="skeleton"></span></div><div class="sub" id="active-tables-sub">—</div></div>
|
|
<div class="card"><h3>Empty tables</h3><div class="big" id="empty-tables"><span class="skeleton"></span></div><div class="sub" id="empty-tables-sub">—</div></div>
|
|
<div class="card"><h3>Total rows</h3><div class="big" id="total-rows"><span class="skeleton"></span></div><div class="sub">aggregated</div></div>
|
|
</div>
|
|
|
|
<h2>Schemas breakdown</h2>
|
|
<div class="grid" id="schemas-grid"></div>
|
|
|
|
<h2>Critical business tables</h2>
|
|
<div class="card">
|
|
<table>
|
|
<thead><tr><th>Table</th><th>Description</th><th>Rows</th><th>Status</th></tr></thead>
|
|
<tbody id="critical-tbody"><tr><td colspan="4" style="text-align:center;padding:24px"><span class="skeleton"></span></td></tr></tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<h2>Top 20 tables by row count</h2>
|
|
<div class="card">
|
|
<table>
|
|
<thead><tr><th>#</th><th>Table</th><th>Rows</th><th>Bar</th></tr></thead>
|
|
<tbody id="top-tbody"><tr><td colspan="4" style="text-align:center;padding:24px"><span class="skeleton"></span></td></tr></tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div class="refresh" id="refresh-info">Connecting to /api/db-stats-live.php...</div>
|
|
|
|
<div id="toast"></div>
|
|
|
|
<script>
|
|
function showToast(msg, type='error') {
|
|
const t = document.getElementById('toast');
|
|
t.textContent = msg;
|
|
t.className = type === 'ok' ? 'toast-ok' : '';
|
|
t.style.display = 'block';
|
|
setTimeout(() => t.style.display = 'none', 5000);
|
|
}
|
|
function fmt(n) { return (n || 0).toLocaleString('fr-FR'); }
|
|
|
|
async function loadData() {
|
|
try {
|
|
const resp = await fetch('/api/db-stats-live.php');
|
|
if (!resp.ok) throw new Error('HTTP ' + resp.status);
|
|
const d = await resp.json();
|
|
if (d.error) throw new Error(d.error);
|
|
|
|
// Overview
|
|
const s = d.summary || {};
|
|
document.getElementById('total-tables').textContent = fmt(s.total_tables);
|
|
document.getElementById('total-tables-sub').textContent = 'PostgreSQL admin+ethica+weval';
|
|
document.getElementById('active-tables').textContent = fmt(s.active_tables);
|
|
document.getElementById('active-tables-sub').textContent = 'Tables with data';
|
|
document.getElementById('empty-tables').textContent = fmt(s.empty_tables);
|
|
document.getElementById('empty-tables-sub').textContent = s.total_tables ? (Math.round(100*s.empty_tables/s.total_tables)+'% of total') : '-';
|
|
document.getElementById('total-rows').textContent = fmt(s.total_rows);
|
|
|
|
// Schemas
|
|
const sg = document.getElementById('schemas-grid');
|
|
sg.innerHTML = '';
|
|
for (const [name, sc] of Object.entries(s.schemas || {})) {
|
|
const card = document.createElement('div');
|
|
card.className = 'card';
|
|
card.innerHTML = `<h3>${name}</h3>
|
|
<div class="big">${fmt(sc.rows)}</div>
|
|
<div class="sub">${sc.tables} tables · ${sc.empty} vides · ${sc.tables - sc.empty} actives</div>
|
|
<div class="bar-container"><div class="bar" style="width:${sc.tables ? 100*(sc.tables-sc.empty)/sc.tables : 0}%"></div></div>`;
|
|
sg.appendChild(card);
|
|
}
|
|
|
|
// Critical
|
|
const ct = document.getElementById('critical-tbody');
|
|
ct.innerHTML = '';
|
|
for (const [tbl, info] of Object.entries(d.critical_status || {})) {
|
|
const rows = info.rows;
|
|
let badge = 'info';
|
|
if (rows === null) badge = 'warn';
|
|
else if (rows === 0) badge = 'empty';
|
|
else if (rows > 1000) badge = 'active';
|
|
const status = rows === null ? 'MISSING' : rows === 0 ? 'EMPTY' : rows > 1000 ? 'ACTIVE' : 'SMALL';
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = `<td><code>${tbl}</code></td>
|
|
<td style="color:#9ca8d3">${info.desc}</td>
|
|
<td class="num">${rows === null ? '—' : fmt(rows)}</td>
|
|
<td><span class="badge ${badge}">${status}</span></td>`;
|
|
ct.appendChild(tr);
|
|
}
|
|
|
|
// Top 20
|
|
const tt = document.getElementById('top-tbody');
|
|
tt.innerHTML = '';
|
|
const max = d.top_tables?.[0]?.rows || 1;
|
|
(d.top_tables || []).forEach((t, i) => {
|
|
const pct = (t.rows / max) * 100;
|
|
const tr = document.createElement('tr');
|
|
tr.innerHTML = `<td>${i+1}</td><td><code>${t.table}</code></td>
|
|
<td class="num">${fmt(t.rows)}</td>
|
|
<td><div class="bar-container"><div class="bar" style="width:${pct}%"></div></div></td>`;
|
|
tt.appendChild(tr);
|
|
});
|
|
|
|
document.getElementById('refresh-info').textContent =
|
|
'Last refresh: ' + new Date(d.ts).toLocaleString('fr-FR') + ' · Auto-refresh in 30s';
|
|
} catch (e) {
|
|
showToast('Erreur: ' + e.message);
|
|
document.getElementById('refresh-info').textContent = 'Error: ' + e.message + ' · Retry in 30s';
|
|
}
|
|
}
|
|
|
|
loadData();
|
|
setInterval(loadData, 30000);
|
|
</script>
|
|
</body></html>
|