fak*_*oid 8 c# process process-monitoring
我正在编写一个程序,它使用.NET性能计数器来获取特定进程的CPU,内存和网络使用情况.
例如,要获取CPU和内存数据Explorer,我创建如下性能计数器:
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";
Run Code Online (Sandbox Code Playgroud)
不幸的是,Process没有属性categoryName允许我获得该进程的网络使用.我可以使用网络接口categoryName来获取任何特定NIC上的整体网络使用情况,但无法将其隔离到任何给定的进程.
我想你只能获取整个系统的网络使用情况。您可以使用此代码:
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();
}
Run Code Online (Sandbox Code Playgroud)
使用 PerformanceCounters,您只能获取 Microsoft 希望您访问的值。
| 归档时间: |
|
| 查看次数: |
1909 次 |
| 最近记录: |