Browse Source

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
Masu Baumgartner 1 year ago
parent
commit
558e237608

+ 1 - 1
Moonlight/Features/Servers/UI/NodeComponents/NodeOverview.razor

@@ -18,7 +18,7 @@
         </div>
         <div class="col-md-3 col-12">
             @{
-                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)}";
             }
 
             <StatCard Value="@memoryText" Description="Memory usage" Icon="bxs-microchip"/>

+ 5 - 1
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)})");
 
                         <ColoredBar Value="percent"/>
                     }