From 271fb1358dccb6fc048914a290b5838b4412e058 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 9 May 2022 13:01:00 +0200 Subject: [PATCH] feat: show usage trends --- src/routes/index.svelte | 194 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 191 insertions(+), 3 deletions(-) diff --git a/src/routes/index.svelte b/src/routes/index.svelte index 73cad3832..224b796b1 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -39,6 +39,11 @@ let cpuWarning = false; let diskWarning = false; + let trends = { + memory: 'stable', + cpu: 'stable', + disk: 'stable' + }; let usage = { cpu: { load: [0, 0, 0], @@ -62,6 +67,36 @@ try { loading.usage = true; const data = await get(`/dashboard.json?usage=true`); + console.log(usage.memory.freeMemPercentage); + if (data.memory.freeMemPercentage === usage.memory.freeMemPercentage) { + trends.memory = 'stable'; + } else { + if (data.memory.freeMemPercentage > usage.memory.freeMemPercentage) { + trends.memory = 'up'; + } else { + trends.memory = 'down'; + } + } + if (data.cpu.usage === usage.cpu.usage) { + trends.cpu = 'stable'; + } else { + if (data.cpu.usage > usage.cpu.usage) { + trends.cpu = 'up'; + } else { + trends.cpu = 'down'; + } + } + + if (data.disk.freePercentage === usage.disk.freePercentage) { + trends.disk = 'stable'; + } else { + if (data.disk.freePercentage > usage.disk.freePercentage) { + trends.disk = 'up'; + } else { + trends.disk = 'down'; + } + } + usage = data; if (usage.memory.freeMemPercentage < 15) { memoryWarning = true; @@ -119,8 +154,59 @@
Free Memory
-
+
{usage?.memory.freeMemPercentage}% + {#if trends.memory === 'stable' || trends.memory === '' || usage.memory.freeMemPercentage === 0} + + + + + {:else if trends.memory === 'up'} + + + + + + + {:else if trends.memory === 'down'} + + + + + + + + {/if}
@@ -139,8 +225,59 @@
CPU Usage
-
+
{(usage?.cpu.usage).toFixed(0)}% + {#if trends.cpu === 'stable' || trends.cpu === '' || usage.cpu.usage === 0} + + + + + {:else if trends.cpu === 'up'} + + + + + + + {:else if trends.cpu === 'down'} + + + + + + + + {/if}
@@ -159,8 +296,59 @@
Free Disk
-
+
{usage?.disk.freePercentage}% + {#if trends.disk === 'stable' || trends.disk === '' || usage.disk.freePercentage === 0} + + + + + {:else if trends.disk === 'up'} + + + + + + + {:else if trends.disk === 'down'} + + + + + + + + {/if}