0

For a given process, how can I learn its

  • cpu usage (%)
  • memory usage (allocated memory)
  • network usage (bytes in/sec, bytes out/sec)

I'm interested in collecting this information from a c# app.

user1367401
  • 1,030
  • 17
  • 26
  • Can you not use perfmon? – Davin Tryon Aug 31 '12 at 21:28
  • 3
    Sorry, just trying to help. All the data is in the WMI database. It is just how you access it. For me, perfmon is the best tool and usually installed where you need it (like production environments). So, if you want a better answer, I suggest you give more detail about what you are trying to do. – Davin Tryon Aug 31 '12 at 21:43
  • I can't use perfmon, because I need to collect this information programatically. – user1367401 Aug 31 '12 at 22:01

3 Answers3

2

It is possible to track all that information with the PerformanceCounter Class.

You can find a more detailed list here as to what kind of information you can track.

coolmine
  • 4,427
  • 2
  • 33
  • 45
2

This article and this example + some c# coding skills are all you need.

Oh, and concerning the process network monitoring, Microsof has a Network Monitor API but YAPM is a superman.

Chibueze Opata
  • 9,856
  • 7
  • 42
  • 65
0

There are classes built into C# that can do this. A Simple Google search "calculate memory usage C#" of "calculate cpu usage C#" brought them up

http://bhaskarrajukonduru-dotnet.blogspot.ca/2010/06/calculate-memory-and-cpu-usage-by-using.html http://stackoverflow.com/questions/278071/how-to-get-the-cpu-usage-in-c (note, you could of searched stackoverflow too) http://www.codeproject.com/Articles/10258/How-to-get-CPU-usage-of-processes-and-threads

Jeff Vanzella
  • 737
  • 5
  • 14