I’m creating a C# based Windows service that will run 24×7 for months on end. I’d like to be able to track general memory usage of my service. It doesn’t need to be exact down to the byte. A general amount allocated will suffice. I’ll be monitoring this for trends in memory consumption. Is GC.GetTotalMemory() an appropriate way to monitor this?
I’m aware of Performance Monitor and the use of counters. However, this service is going to be running on at least 12 different servers. I don’t want to track PM on 12 different servers. The service will persist all performance and memory usage information, from all instances, to a central DB to avoid this, and for easier analysis.
Only if it’s a purely managed-memory application. If any of it is calling off to unmanaged code, the memory allocated there will never be registered with the garbage collector (unless someone remembers to call
GC.AddMemoryPressure).