From 56bf7a0ffbdc834c34925ecdd73d76de532360c7 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Sun, 23 Jul 2023 12:14:33 +0200 Subject: [PATCH] Fix cpu/memory stats widget --- packages/backend/src/daemons/server-stats.ts | 1 + packages/client/src/pages/admin/overview.metrics.vue | 4 ++-- packages/client/src/widgets/server-metric/cpu-mem.vue | 4 ++-- packages/client/src/widgets/server-metric/mem.vue | 4 ++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/backend/src/daemons/server-stats.ts b/packages/backend/src/daemons/server-stats.ts index 7d4fcd25e1..39d81ec914 100644 --- a/packages/backend/src/daemons/server-stats.ts +++ b/packages/backend/src/daemons/server-stats.ts @@ -37,6 +37,7 @@ export default function () { mem: { used: round(memStats.used - memStats.buffers - memStats.cached), active: round(memStats.active), + total: round(memStats.total), }, net: { rx: round(Math.max(0, netStats.rx_sec)), diff --git a/packages/client/src/pages/admin/overview.metrics.vue b/packages/client/src/pages/admin/overview.metrics.vue index cfd497439a..48d407e7d3 100644 --- a/packages/client/src/pages/admin/overview.metrics.vue +++ b/packages/client/src/pages/admin/overview.metrics.vue @@ -84,8 +84,8 @@ const diskAvailable = $computed(() => meta.fs.total - meta.fs.used); function onStats(stats) { cpuUsage = stats.cpu; - memUsage = stats.mem.active / meta.mem.total; - memTotal = meta.mem.total; + memUsage = stats.mem.active / stats.mem.total; + memTotal = stats.mem.total; memUsed = stats.mem.active; memFree = memTotal - memUsed; diff --git a/packages/client/src/widgets/server-metric/cpu-mem.vue b/packages/client/src/widgets/server-metric/cpu-mem.vue index ac7e7f7c1f..67ed3bc7dc 100644 --- a/packages/client/src/widgets/server-metric/cpu-mem.vue +++ b/packages/client/src/widgets/server-metric/cpu-mem.vue @@ -131,7 +131,7 @@ function onStats(connStats) { ]); const memPolylinePointsStats = stats.map((s, i) => [ viewBoxX - (stats.length - 1 - i), - (1 - s.mem.active / props.meta.mem.total) * viewBoxY, + (1 - s.mem.active / s.mem.total) * viewBoxY, ]); cpuPolylinePoints = cpuPolylinePointsStats .map((xy) => `${xy[0]},${xy[1]}`) @@ -153,7 +153,7 @@ function onStats(connStats) { memHeadY = memPolylinePointsStats[memPolylinePointsStats.length - 1][1]; cpuP = (connStats.cpu * 100).toFixed(0); - memP = ((connStats.mem.active / props.meta.mem.total) * 100).toFixed(0); + memP = ((connStats.mem.active / connStats.mem.total) * 100).toFixed(0); } function onStatsLog(statsLog) { diff --git a/packages/client/src/widgets/server-metric/mem.vue b/packages/client/src/widgets/server-metric/mem.vue index 97e7a63ce5..da7ecd81e0 100644 --- a/packages/client/src/widgets/server-metric/mem.vue +++ b/packages/client/src/widgets/server-metric/mem.vue @@ -26,8 +26,8 @@ let usage: number = $ref(0), free: number = $ref(0); function onStats(stats) { - usage = stats.mem.active / props.meta.mem.total; - total = props.meta.mem.total; + usage = stats.mem.active / stats.mem.total; + total = stats.mem.total; used = stats.mem.active; free = total - used; }