0

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.

Obsidian
  • 3,719
  • 8
  • 17
  • 30
Arlandria
  • 1
  • 2
  • 2
    If you have the possibility to upgrade to .NET 5.0, then there's a new `GC.GetGCMemoryInfo()` method that gets a lot of interesting data about the current memory usage. But sadly, it's really .NET 5 only. – PMF May 06 '21 at 19:06

1 Answers1

0

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.

Jonathan Van Dam
  • 630
  • 9
  • 23
Arlandria
  • 1
  • 2