【发布时间】:2018-06-19 12:19:30
【问题描述】:
我想使用 Process 类获取我的应用程序池的内存使用情况。到目前为止,这是我的代码:
ServerManager serverManager = new ServerManager();
ApplicationPoolCollection applicationPoolCollection = serverManager.ApplicationPools;
Process process = Process.GetProcessById(applicationPoolCollection.Where(p => p.Name == "mywebsite.com").First().WorkerProcesses[0].ProcessId);
我可以获得 Process 类,但我如何知道它当前使用的 RAM 量是多少?我确实看到了像PagedMemorySize64 和NonpagedSystemMemorySize64 这样的属性。哪一个会给我它目前占用的正确 RAM?
我不能像这样使用PerformanceCounter:
PerformanceCounter performanceCounter = new PerformanceCounter();
performanceCounter.CategoryName = "Process";
performanceCounter.CounterName = "Working Set";
performanceCounter.InstanceName = process.ProcessName;
Console.WriteLine(((uint)performanceCounter.NextValue() / 1024).ToString("N0"));
ProcessName 的原因会返回 w3p,因此 PerformanceCounter 会在控制台中写入 IIS RAM 的总使用量,这不是我想要的。
我只需要应用程序池的 RAM 使用量。因此我认为我的答案在于 Process 类而不是 PerformanceCounter
感谢任何帮助。
【问题讨论】:
-
您需要一定数量的 RAM,还是分配给进程的内存数量?