From 558e237608aca16f86e5411eb1d0ba48f6b9b71f Mon Sep 17 00:00:00 2001 From: Masu Baumgartner Date: Mon, 6 May 2024 09:15:27 +0200 Subject: [PATCH] Small fix for node memory calculation Made calculation accurate using: https://stackoverflow.com/questions/41224738/how-to-calculate-system-memory-usage-from-proc-meminfo-like-htop --- .../Features/Servers/UI/NodeComponents/NodeOverview.razor | 2 +- Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Moonlight/Features/Servers/UI/NodeComponents/NodeOverview.razor b/Moonlight/Features/Servers/UI/NodeComponents/NodeOverview.razor index 93c5297..13ca692 100644 --- a/Moonlight/Features/Servers/UI/NodeComponents/NodeOverview.razor +++ b/Moonlight/Features/Servers/UI/NodeComponents/NodeOverview.razor @@ -18,7 +18,7 @@
@{ - var memoryText = $"{Formatter.FormatSize(Status.Hardware.Memory.Total - Status.Hardware.Memory.Available - Status.Hardware.Memory.Free)} / {Formatter.FormatSize(Status.Hardware.Memory.Total)}"; + var memoryText = $"{Formatter.FormatSize(Status.Hardware.Memory.Total - (Status.Hardware.Memory.Available + Status.Hardware.Memory.Cached))} / {Formatter.FormatSize(Status.Hardware.Memory.Total)}"; } diff --git a/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor b/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor index ce9bda1..b44e94b 100644 --- a/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor +++ b/Moonlight/Features/Servers/UI/Views/Admin/Nodes/Index.razor @@ -78,7 +78,11 @@ @if (NodeStats.ContainsKey(context!.Id) && NodeStats[context.Id] != null) { var memory = NodeStats[context!.Id]!.Hardware.Memory; - var percent = Math.Round(((float)memory.Total - memory.Available - memory.Free) / memory.Total * 100, 2); + + var used = memory.Total - (memory.Available + memory.Cached); + var percent = Math.Round((float) used / memory.Total * 100F, 2); + + //Logger.Debug($"Used: {used} Total: {memory.Total} => {percent}% ({Formatter.FormatSize(used)} / {Formatter.FormatSize(memory.Total)})"); }