监视特定进程的网络性能

本文关键字:网络 性能 进程 监视 | 更新日期: 2023-09-27 18:10:41

我正在编写一个程序,它使用。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来获得任何特定网卡上的整体网络使用情况,但不能将其隔离到任何给定的进程。

监视特定进程的网络性能

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

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希望您访问的值。