![]() |
|
[.NET] Using Performance Counters to monitor CPU and RAM usage - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [.NET] Using Performance Counters to monitor CPU and RAM usage (/showthread.php?tid=4573070) |
Using Performance Counters to monitor CPU and RAM usage - ecaep42 - Dec 7, 2014 Hello, I'm pretty sure this is known but might as well try, seeing we could use something that isn't a rat or me asking for something (lol :D), so I will show you how you can use Performance Counters to monitor cpu and ram usage. Plus I'm gonna be lazy and make them via coding! Now before we begin, performance counters aren't only used for monitoring CPU and RAM usage, it can monitor other things too, like Caching, HTTP Services, and even Windows Media Player! It's mostly what you choose and how you use it, but I will be focusing on CPU and RAM usage. Firstly we need to add the control, but what I'm gonna do is just call it within coding. Code Dim cpuUsed As New PerformanceCounter With {.CategoryName = "Processor", .CounterName = "% Processor Time", .InstanceName = "_Total"}Code Dim cpuCore1 As New PerformanceCounter With {.CategoryName = "Processor", .CounterName = "% Processor Time", .InstanceName = "0"}Well, now we need to get the value of it.. so what are we gonna do? We're gonna use a progress bar! Code ProgressBar1.Value = cpuUsed.NextValueNow, we need to monitor RAM usage, so.. New perfcounters! Code Dim ramTotal As New PerformanceCounter With {.CategoryName = "Memory", .CounterName = "% Committed Bytes In Use"}So now we need to get the value from that too.. how do we do it? Same as above! Code ProgressBar1.Value = ramTotal.NextValueThat's practically the use of Performance Counters to monitor CPU and RAM usage. Now, if you excuse me... I need to figure out how to use the Windows Media Player Category with them.[/code] I may or may not edit this in the quick future. * - He B TeMy - Dec 7, 2014 yea... a google search would end up with this... Anyway, i don't like performanceCounter to get the % Ram in use, because there's API's for that, and i like API's. But for CPU i believe this is the only way.. Nice explanation though. |