From 60c0de670c059be7171ab229086cdaad35dae041 Mon Sep 17 00:00:00 2001 From: pptx704 Date: Mon, 13 Apr 2026 04:16:53 +0600 Subject: [PATCH] Extract MetricsPanel component and use it in admin capsule detail page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moves all Chart.js metrics logic (polling, smoothing, chart init/update) into a reusable MetricsPanel component with 'full' and 'compact' layout modes. The admin capsule detail page now reuses MetricsPanel, TerminalTab, and FilesTab — no duplicated code. --- .../src/lib/components/MetricsPanel.svelte | 345 ++++++++++++++++++ .../routes/admin/capsules/[id]/+page.svelte | 286 +-------------- 2 files changed, 352 insertions(+), 279 deletions(-) create mode 100644 frontend/src/lib/components/MetricsPanel.svelte diff --git a/frontend/src/lib/components/MetricsPanel.svelte b/frontend/src/lib/components/MetricsPanel.svelte new file mode 100644 index 0000000..a1e6f0f --- /dev/null +++ b/frontend/src/lib/components/MetricsPanel.svelte @@ -0,0 +1,345 @@ + + + + +
+ +
+ {#if !metricsLoading} + + + Live + + {:else} +
+ {/if} + +
+ {#each METRIC_RANGES as r, i} + + {/each} +
+
+ + {#if metricsError} +
+ + + + Could not load metrics: {metricsError}. Will retry automatically. +
+ {/if} + + +
+ + +
+
+
+ + CPU Usage +
+ {#if latestCpu !== null} +
+ {latestCpu.toFixed(1)} + % +
+ {:else if metricsLoading} + + {/if} +
+
+ +
+
+ + +
+
+
+ + RAM Usage +
+ {#if latestRamMB !== null} +
+ {latestRamMB.toFixed(0)} + MB +
+ {:else if metricsLoading} + + {/if} +
+
+ +
+
+ +
+
diff --git a/frontend/src/routes/admin/capsules/[id]/+page.svelte b/frontend/src/routes/admin/capsules/[id]/+page.svelte index 7765314..11dfc46 100644 --- a/frontend/src/routes/admin/capsules/[id]/+page.svelte +++ b/frontend/src/routes/admin/capsules/[id]/+page.svelte @@ -1,10 +1,11 @@ @@ -349,9 +153,7 @@ Capsules
- {capsuleId} - - -
{capsule.template} / {capsule.vcpus}v · {capsule.memory_mb}MB
-
{#if capsule.status === 'running' || capsule.status === 'paused'} @@ -396,91 +195,20 @@
-
- +
- - {#if metricsAvailable}
- -
-
- - - Live - -
-
- {#each METRIC_RANGES as r, i} - - {/each} -
-
- - -
- -
-
-
- - CPU Usage -
- {#if latestCpu !== null} -
- {latestCpu.toFixed(1)} - % -
- {:else if metricsLoading} - - {/if} -
-
- -
-
- - -
-
-
- - RAM Usage -
- {#if latestRamMB !== null} -
- {latestRamMB.toFixed(0)} - MB -
- {:else if metricsLoading} - - {/if} -
-
- -
-
-
+
{/if} - -
+