I have a server which is idling below 5% cpu load most of the time, except from a few times a day where I can see some minor cpu spikes. I found out about this by using PRTG.

How can I find out what process is causing the cpu spikes? It's easy to monitor WMI CPU load with PRTG, but what I would also really need is a way to log the most CPU-Intensive processes in regular intervals.

I guess this can be done with perfmon, but which performance counters do I need for this job?



  • There are two built-in Data Collector sets in Perfmon that look like they'll give you what you need. If not, you can create your own Data Collector set. – joeqwerty Jan 3 '13 at 22:59

Data Collector Sets are nice, professional, and they can be triggered by an event such as... high CPU usage.

You could also use Powershell.

$proc = Get-Process | Sort-Object TotalProcessorTime -Descending -EA 0 | Select -First 1
"$(Get-Date) - $($proc.Name) - $($proc.TotalProcessorTime)" | Out-File file.txt -Append

Save that as a *.ps1. Run it as a Scheduled Task every 5 minutes or whatever. The first line finds the top 1 most "CPU intensive" process at the time. The second line logs it to a file with a time stamp.

You could also get as fancy as you can imagine, by having the script only log if the system's total CPU usage is over 99% or something like that. The sky's the limit.

  • My pleasure. I just realized that the Append parameter of Out-File might not have been added until PS v3, so if you have PS v2 or your Out-File cmdlet doesn't have an -Append parameter, just use Add-Content instead. – Ryan Ries Jan 4 '13 at 1:15
  • Thanks. Just one additional question: The TotalProcessorTime is good for finding general CPU hogs, but for CPU spikes I'd like to see the current CPU usage. Is there any way to get that via Powershell? – Adrian Grigore Jan 4 '13 at 11:01
  • Well this is just an example, but foreach($_ In Get-WmiObject Win32_PerfFormattedData_PerfOS_Processor) { this will loop through each logical processor here } For each logical proc in the example above, there are PercentUserTime, PercentPrivilegedTime, PercentProcessorTime, etc. – Ryan Ries Jan 4 '13 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.