c# - 监视特定进程的网络性能

标签 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 没有属性允许我获取该进程的网络使用情况。我可以使用网络接口(interface) 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();  
}

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

关于c# - 监视特定进程的网络性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16200034/

相关文章:

linux - 为什么我不能在 Linux 中创建 50k 进程?

linux - 如何在 Linux 中找到正在运行的进程的单个线程的 %RAM 和 %CPU 消耗?

.net - C:\WINDOWS\assembly\NativeImages_v2.0.50727_32\index3a0.dat用于什么?

c# - IronPython 脚本调试

java - ProcessBuilder - 启动另一个进程/JVM - 如何?

c#有没有办法让我的基类和派生类分别实现接口(interface)方法?

process - 编译 Go 编程语言有多难?

c# - 如何从 Windows8 商店应用程序中的字节数组获取流

C#:为什么 LinkedList 没有采用谓词的 RemoveAll 方法?