I'm trying to write small IIS process monitor (CPU and memory usage) which should be as light for the system as possible. All I need is IIS App Pool Name, current Memory Usage and current CPU Usage.
I've managed to do it without bigger problems using these two commands:
using (var srvman = new ServerManager())
{
workerProcesses = srvman.WorkerProcesses;
}
and
processes = Process.GetProcesses().Where(processItem => processItem.ProcessName.Contains("w3wp") || processItem.ProcessName.Contains("php-cgi"))
The first one returns running app pools with process ID's and second one is returning process information from system (so here is where I'm getting CPU and Memory usage). Joining this two informations gives me almost what I want. The one exception is PHP apps which are running on IIS.
For PHP apps, php-cgi.exe
processes are being spawned which I need to correlate to the IIS App Pool worker process. Do you have any idea how to connect php-cgi.exe
processes to their w3wp.exe
parents?
Here is an example of the output I would like to produce:
1x w3wp.exe for site.com is using 15MB memory
4x php-cgi.exe is using 4x 15MB = 60MB memory
I'm planning to sum this information (which in this scenario would be 75 MB of memory usage for site.com).