我正在编写一个程序,它使用.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上的总体网络使用情况,但不能将其隔离到任何给定的进程。
发布于 2013-04-25 20:18:53
我想您只能获得整个系统的网络使用情况。您可以使用以下代码:
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,您只能获取微软希望您有权访问的值。
https://stackoverflow.com/questions/16200034
复制相似问题