监控特定流程的网络性能

时间:2013-04-24 18:57:23

标签: c# process process-monitoring

我正在编写一个程序,它使用.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";

不幸的是,进程categoryName没有允许我获取该进程的网络使用的属性。我可以使用网络接口categoryName来获取任何特定NIC的整体网络使用情况,但无法将其与任何给定的进程隔离。

1 个答案:

答案 0 :(得分:0)

我想你只能获得整个系统的网络使用率。您可以使用以下代码:

GetCounterValue(_netRecvCounters[index], "Network Interface", "Bytes Received/sec",      _instanceNames[index]):

double GetCounterValue(PerformanceCounter pc, string categoryName, string counterName, string instanceName)
{
    pc.CategoryName = categoryName;
    pc.CounterName = counterName;
    pc.InstanceName = instanceName;
    return pc.NextValue();  
}

使用PerformanceCounters,您只能获得Microsoft希望您有权访问的值。

相关问题