2015-02-05 43 views
1

我想要在任务管理器窗口的性能选项卡中获得性能数据。如何获得性能数据?

我得到这个代码:

using (PerformanceCounter pCounter = new PerformanceCounter()) 
{    
    pCounter.CategoryName = "Processor"; //this get me the cpu usage 
    pCounter.CounterName = "% Processor Time"; 
    pCounter.InstanceName = "_Total"; 

    // will always start at 0 
    pCounter.NextValue(); 
    System.Threading.Thread.Sleep(1000); 
    //now matches task manager reading 
    float cpuUsage = pCounter.NextValue(); 

    pCounter.CategoryName = "Memory"; 
    pCounter.CounterName = "Available MBytes"; //this gets me the available memory 
    pCounter.InstanceName = string.Empty; 
} 

我还需要:

  • 的时间(时间服务器是活动的HH:MM:SS)
  • 的进程数
  • 线程数
  • 以太网使用

我不知道如何获取这些数据...

+0

snmp呢? – 2015-02-05 13:44:24

+0

我不知道它是什么... – 2015-02-05 13:46:10

+0

[进程数(https://msdn.microsoft.com/en-us/library/1f3ys1f9%28v=vs.110%29.aspx)。 [线程数](https://msdn.microsoft.com/en-us/library/system.collections.readonlycollectionbase.count(V = vs.110)的.aspx)以太网使用情况稍微更复杂一些,发现了[代码审查.SE](http://codereview.stackexchange.com/questions/28367/basic-network-utilisation-display)文章。 [服务器运行时间](http://stackoverflow.com/a/972189/3191303)。有时将每个项目分解成单独的问题将有助于找出比整体更容易的解决方案。 – AWinkle 2015-02-05 13:50:16

回答