Dear kusumah
A PRTG sensor cannot handle tables, only strings without line breaks. A possible sensor output could be:
24:chrome#35 uses 24%, PRTG Server uses 6%, chrome#33 uses 6%
The part in front of the colon, the number 24, would be the sensor data, in this case just the CPU load of the top process. The part after the colon is the sensor message string. The string will not be part of the historic data, it only contains information for the current status.
You can return several channels, using the XML structure conforming to the Advanced sensor API. Still, only one sensor message will be available. And it is not possible to delete sensor channels once created, so it would not make sense to create a channel per process.
This would be (an overly simple) top 3 sensor:
$processes=gwmi Win32_PerfFormattedData_PerfProc_Process | select IDProcess,Name,PercentProcessorTime | where { $_.Name -ne "_Total" -and $_.Name -ne "Idle"} | sort PercentProcessorTime -Descending | select -First 3
$top1=new-object PSObject -Property @{
name =$Processes[0].Name
CPU =$Processes[0].PercentProcessorTime
description=(Get-Process -Id $Processes[0].IDProcess).Description
}
$top2=new-object PSObject -Property @{
name =$Processes[1].Name
CPU =$Processes[1].PercentProcessorTime
description=(Get-Process -Id $Processes[1].IDProcess).Description
}
$top3=new-object PSObject -Property @{
name =$Processes[2].Name
CPU =$Processes[2].PercentProcessorTime
description=(Get-Process -Id $Processes[2].IDProcess).Description
}
$top1cpu=$top1.CPU -as [string]
$top2cpu=$top2.CPU -as [string]
$top3cpu=$top3.CPU -as [string]
if ($top1.description.length -gt 0) {
$top1.name=$top1.description
}
if ($top2.description.length -gt 0) {
$top2.name=$top2.description
}
if ($top3.description.length -gt 0) {
$top3.name=$top3.description
}
$topall3=$top1.CPU+$top2.CPU+$top3.CPU
$result=$topall3 -as [string]
$result=$result+":"+$top1.name+" ("+$top1cpu+"%), "+$top2.name+" ("+$top2cpu+"%), "+$top3.name+" ("+$top3cpu+"%)"
write-host $result
This is a standard Exe/Script sensor, not an Exe/Script Advanced sensor, intentionally written in a simple way.
Add comment