Pinkstink-Rust / Rust-Server-Metrics

A metrics gathering HarmonyMod for Rust game servers
MIT License
62 stars 24 forks source link

Total memory usage doesn't work in linux/docker containers #30

Open farkas1121 opened 3 months ago

farkas1121 commented 3 months ago

I'm using pterodactyl panel on linux to run my servers and noticed that server metrics reports the total memory usage to be 0. It seems like Rust's native dll returns the wrong value trough SystemInfoEx.systemMemoryUsed.

One possible way to avoid this issue would be to get the list of processes and sum their memory usage like this.

            using System.Diagnostics;

            long memoryUsageBytes = 0;
            foreach (var process in Process.GetProcesses())
            {
                memoryUsageBytes += process.WorkingSet64;
            }

Or just get the memory usage of the current server like this:

            using System.Diagnostics;

            Process currentProcess = Process.GetCurrentProcess();
            long memoryUsageBytes = currentProcess.WorkingSet64;

Not sure whether there are any downsides or a better solution, but I think it would be worth it to look into a new way of getting the memory usage on linux systems.

Jexs commented 2 weeks ago

Something we can look into adding. I think most users also run system metrics which they use to monitor memory usage which is why it was never added. Regardless we can look into it at some point.

I don't have the bandwidth right this minute, so if anyone wants to open a PR feel free. If not I'll get to it at some point.