My system often has performance issues.
Is there a way to determine the Windows process that causes the highest CPU load?
Article Comments
This article applies to PRTG Network Monitor 14 or later
Showing the Process with the Highest CPU Load
You can use the following PowerShell (PS1) script with the EXE/Script sensor.
- Copy the script below into an editor and save it as .ps1 file.
- Put the file into the \Custom Sensors\EXE subfolder of your PRTG installation directory.
- Add an EXE/Script sensor to your PRTG installation and choose this script during sensor setup.
Note: This script will work only on the local machine (either PRTG local probe, or a PRTG remote probe).
param(
[int]$minload
)
$processes=Get-WMIObject Win32_PerfFormattedData_PerfProc_Process | select IDProcess,Name,PercentProcessorTime | where { $_.Name -ne "_Total" -and $_.Name -ne "Idle"} | sort PercentProcessorTime -Descending | select -first 1
$topname=$Processes[0].Name
$topCPU=$Processes[0].PercentProcessorTime
$topdesc=(Get-Process -Id $Processes[0].IDProcess).Description
$result=$topCPU -as [string]
if ($topdesc.length -gt 0) {
$topname=$topdesc
}
$result=$result+":"+$topname
if ($topCPU -lt $minload) {
$result="0:No process at or above $minload%"
}
write-host $result
This sensor will show the process with the highest CPU load in the sensor status message. This message will not be saved by PRTG. It is not possible to use the historic data to see which process previously had the highest CPU load.
The script shows the thread's description and if none exists, the thread's name.
Oct, 2014 - Permalink
Hello,
I have successfully managed to get Top CPU load for processes on remote computers,
using the code above with some modifications here:
param([string] $comp,
[int] $minload)
$processes=Get-WmiObject -computer $comp -Class Win32_PerfFormattedData_PerfProc_Process | select IDProcess,Name,PercentProcessorTime | where { $_.Name -ne "_Total" -and $_.Name -ne "Idle"} | sort PercentProcessorTime -Descending | select -first 1
$topname=$Processes[0].Name
$topCPU=$Processes[0].PercentProcessorTime
$topdesc=(gwmi Win32_Process -ComputerName $comp | where {$_.ProcessId -eq $Process.IDProcess}).Description
$result=$topCPU -as [string]
if ($topdesc.length -gt 0) {
$topname=$topdesc
}
$result=$result+":"+$topname
if ($topCPU -lt $minload) {
$result="0:No process at or above $minload%"
}
write-host $result
Jun, 2018 - Permalink
Hello zoolaNder,
Trying to run the script above, however, PRTG constantly shows “No Process at or above 0%”
The script also fails at console.
I am not proficient in PS. Can you tell me if there are any variables that I need to change, for example, the conputer name?
Aug, 2018 - Permalink
This article applies to PRTG Network Monitor 14 or later
Showing the Process with the Highest CPU Load
You can use the following PowerShell (PS1) script with the EXE/Script sensor.
Note: This script will work only on the local machine (either PRTG local probe, or a PRTG remote probe).
param( [int]$minload ) $processes=Get-WMIObject Win32_PerfFormattedData_PerfProc_Process | select IDProcess,Name,PercentProcessorTime | where { $_.Name -ne "_Total" -and $_.Name -ne "Idle"} | sort PercentProcessorTime -Descending | select -first 1 $topname=$Processes[0].Name $topCPU=$Processes[0].PercentProcessorTime $topdesc=(Get-Process -Id $Processes[0].IDProcess).Description $result=$topCPU -as [string] if ($topdesc.length -gt 0) { $topname=$topdesc } $result=$result+":"+$topname if ($topCPU -lt $minload) { $result="0:No process at or above $minload%" } write-host $result
This sensor will show the process with the highest CPU load in the sensor status message. This message will not be saved by PRTG. It is not possible to use the historic data to see which process previously had the highest CPU load.
The script shows the thread's description and if none exists, the thread's name.
Oct, 2014 - Permalink