Search code examples
c#linux.net-coreoperating-system.net-core-3.1

Getting memory usage of process from .Net Core app on Linux machine


I'm trying to get the total memory usage of current process from the .netcore application.

System.Diagnostics.Process.GetCurrentProcess().PagedMemorySize64 works fine on windows but it returns zero on Linux machine. I also tried System.Diagnostics.PerformanceCounter package to get the value but it throws platform is not supported exception.

I'm using .netcore 3.1 as framework.


Solution

  • By following the answer to getting CPU and memory usage of a docker container. I simply read the file at the location /sys/fs/cgroup/memory/memory.usage_in_bytes and parsed it into and int variable.