我正在编写一个程序,使用.NET性能计数器获取特定进程的CPU、内存和网络使用情况。
例如,要获取Explorer
的CPU和内存数据,我可以创建如下的性能计数器:
PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Process";
PC.CounterName = "% Processor Time";
PC.InstanceName = "Explorer";
PerformanceCounter PC = new PerformanceCounter();
PC.CategoryName = "Process";
PC.CounterName = "Working Set - Private";
PC.InstanceName = "Explorer";
很遗憾,Process的categoryName
属性不能让我获取该进程的网络使用情况。我可以使用Network Interface的categoryName
属性来获取特定网卡上的整体网络使用情况,但无法将其隔离到任何给定的进程中。