I’m working on a simple ASP .NET health checker and I’ve run into a few obstacles.
1) I need to be able to get the full non-paged memory usage from a remote machine (on same network). I’ve tried using System.Diganostics.Process.NonpagedSystemMemorySize64 however I’ve come to realize that the kernel’s nonpaged usage is going to be missing from that total. Here is a quick sample of what I was doing:
Process[] myprocess = Process.GetProcesses("computername");
foreach (Process p in myprocess)
{
nonpaged += p.NonpagedSystemMemorySize64;
}
2) I can overcome that locally by using System.Diagnostics.PerformanceCounter however you can only access the API for that class locally. Is there another class that would suit my needs?
Any help would be appreciated.
One solution I used for this to grab machine diagnostics previously was to use DLLImport.
See P-Invoke
Hope this helps
Pete
In answer to your comment
When using DLL import you have to declare the function wrapper yourself. In the code below you can see the public static extern void which is saying to the compiler that it is an external call to a function called GlobalMemoryStatus which is located in the DLLImported kernel32.dll. The MemoryStatus struct which is an output parameter of the functionis populated inside the kernel32 dll and is returned back fully populated.
Copy this into your code and read the comments they should help you to understand it.
This should allow you to get the memory diagnostics of the machine.