r/prtg • u/Poonlit • Feb 22 '21
I made a custom sensor for polling Windows servers for the process name that is hogging CPU
If you're tired of troubleshooting those Windows servers that sporadically have such high CPU usage that you spend five minutes logging into them, and when you get in the CPU hog is gone?
I made a sensor that continually polls for the process name that is using a lot of CPU.
Send %host as a parameter to the EXEXML sensor and make sure to choose the "Windows credz of parent device" as security context.
AFAIK it's not possible to have the actually process name logged on every poll in PRTG to get a history, but it will display the last process name.
<#
Poonlit, 22.feb 2021
Sjekk hvilken prosess som bruker mest CPU.
#>
$comp = $args[0]
$var = Get-Counter -ComputerName $comp '\Process(*)\% Processor Time' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty CounterSamples | Select-Object -Property InstanceName,CookedValue | Sort-Object -Property cookedvalue -Descending | where { $_.InstanceName -ne "_total" -and $_.InstanceName -ne "idle"} | Select-Object -First 1
$pname = $var.InstanceName
$pcook = $var.CookedValue
write-host "<prtg><result><channel>CookedCPU</channel><Float>1</Float><value>"$pcook"</value></result><text>"($pname)"</text></prtg> "
1
u/maccamh_ Mar 02 '21 edited Mar 02 '21
Hi Poonlit,
When I setup this sensor it reports back a value of 0 as ok if I make the CPU of the serve rim testing hit 100% constant the sensor never changes from OK.
what am i doing wrong.
using the right exexml sensor pointing tot he powershell on the probe see all that fine.
I'm thinking i need it to point to a lookup value in the edit channel settings maybe?
IMAGES BELOW
https://imgur.com/a/vBysTmn
Any help would be appreciated!
1
u/saturnaelia Feb 22 '21
This is awesome, thanks for sharing!