Add shared statistics and Prometheus metrics
This commit is contained in:
1 parent
f5825e806b
commit
2e8a394857
15 files changed
+501
-19
No files matched your search
+19
@@ -233,6 +233,23 @@ function formatBytes(value) {
|
||||
return `${size.toFixed(unit ? 1 : 0)} ${units[unit]}`;
|
||||
}
|
||||
|
||||
async function refreshStatistics() {
|
||||
const status = $('#statisticsStatus');
|
||||
try {
|
||||
const response = await fetch('/api/stats', { cache: 'no-store' });
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const statistics = await response.json();
|
||||
const format = new Intl.NumberFormat();
|
||||
$('#statSyncs').textContent = format.format(statistics.syncs || 0);
|
||||
$('#statAssets').textContent = format.format(statistics.assets || 0);
|
||||
$('#statImages').textContent = format.format(statistics.images || 0);
|
||||
$('#statVideos').textContent = format.format(statistics.videos || 0);
|
||||
status.textContent = `${formatBytes(statistics.bytes || 0)} transferred · since statistics were enabled`;
|
||||
} catch {
|
||||
status.textContent = 'Statistics temporarily unavailable';
|
||||
}
|
||||
}
|
||||
|
||||
function handle(message) {
|
||||
switch (message.type) {
|
||||
case 'hello':
|
||||
@@ -295,4 +312,6 @@ ui.abort.addEventListener('click', () => {
|
||||
});
|
||||
|
||||
setConnection('idle', 'Idle');
|
||||
refreshStatistics();
|
||||
setInterval(refreshStatistics, 30_000);
|
||||
if (restoreShareFragment()) inspect();
|
||||
+14
-1
@@ -28,6 +28,19 @@
|
||||
<div id="connection" class="connection idle"><i></i><span>Idle</span></div>
|
||||
</header>
|
||||
|
||||
<section class="statistics" aria-labelledby="statisticsTitle">
|
||||
<div class="statistics-heading">
|
||||
<div><p class="eyebrow">Shared service totals</p><h2 id="statisticsTitle">What we have synchronized</h2></div>
|
||||
<span id="statisticsStatus">Loading…</span>
|
||||
</div>
|
||||
<div class="statistics-grid">
|
||||
<div><strong id="statSyncs">—</strong><span>completed syncs</span></div>
|
||||
<div><strong id="statAssets">—</strong><span>assets synchronized</span></div>
|
||||
<div><strong id="statImages">—</strong><span>photos</span></div>
|
||||
<div><strong id="statVideos">—</strong><span>videos</span></div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="workspace" aria-label="Share links">
|
||||
<article id="leftCard" class="share-card left">
|
||||
<div class="card-heading">
|
||||
@@ -87,7 +100,7 @@
|
||||
<footer>
|
||||
<span>Ephemeral by design</span>
|
||||
<span>Checksum comparison</span>
|
||||
<span>Originals streamed in memory</span>
|
||||
<span>One temporary asset at a time</span>
|
||||
<span>No deletion</span>
|
||||
</footer>
|
||||
</main>
|
||||
|
||||
@@ -46,6 +46,15 @@ main { width: min(1180px, calc(100% - 36px)); margin: 0 auto; padding: 58px 0 32
|
||||
.connection.connected { color: var(--green); }.connection.connected i { background: var(--green); }
|
||||
.connection.disconnected { color: var(--red); }.connection.disconnected i { background: var(--red); }
|
||||
|
||||
.statistics { margin-bottom: 18px; padding: 20px 22px; border: 1px solid var(--line); border-radius: 18px; background: rgba(18,25,39,.62); }
|
||||
.statistics-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 17px; }
|
||||
.statistics-heading h2 { margin: 5px 0 0; font-size: 1.05rem; }
|
||||
.statistics-heading > span { color: #64748b; font-size: .68rem; }
|
||||
.statistics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
|
||||
.statistics-grid div { display: flex; flex-direction: column; gap: 4px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: rgba(0,0,0,.16); }
|
||||
.statistics-grid strong { color: var(--cyan); font-size: 1.55rem; font-variant-numeric: tabular-nums; }
|
||||
.statistics-grid span { color: var(--muted); font-size: .7rem; }
|
||||
|
||||
.workspace { display: grid; grid-template-columns: 1fr 64px 1fr; align-items: stretch; }
|
||||
.share-card, .controls, .activity { border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(18px); box-shadow: 0 24px 80px rgba(0,0,0,.22); }
|
||||
.share-card { padding: 26px; transition: border-color .2s, transform .2s; }
|
||||
@@ -108,6 +117,7 @@ footer span::before { content: '✓'; color: var(--green); margin-right: 7px; }
|
||||
.hero { grid-template-columns: auto 1fr; }.connection { grid-column: 2; justify-self: start; }
|
||||
.brand-mark { width: 48px; height: 48px; transform: scale(.75); transform-origin: left center; }
|
||||
.workspace { grid-template-columns: 1fr; gap: 10px; }.share-card.left, .share-card.right { border-radius: 17px; }
|
||||
.statistics-grid { grid-template-columns: repeat(2, 1fr); }
|
||||
.exchange { flex-direction: row; height: 38px; border: 0; background: transparent; transform: rotate(90deg); }
|
||||
.sync-options { grid-template-columns: 1fr; }.activity-heading { align-items: flex-start; }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user