Something like this should do the trick:
param(
$computerName = "localhost",
$ignoreList = @("_Total", "svchost*")
)
$channelTemplateCPULoad = @"
<result>
<channel>[{0}] CPU Load</channel>
<value>{1}</value>
<unit>CPU</unit>
<float>1</float>
<DecimalMode>2</DecimalMode>
</result>
"@
$channelTemplateMemoryUsage = @"
<result>
<channel>[{0}] Memory Usage</channel>
<value>{1}</value>
<Unit>BytesDisk</Unit>
<VolumeSize>MegaByte</VolumeSize>
<Float>1</Float>
</result>
"@
$properties=@(
@{Name="Process Name"; Expression = {$_.name}},
@{Name="CPU (%)"; Expression = {$_.PercentProcessorTime}},
@{Name="Memory (MB)"; Expression = {[Math]::Round(($_.workingSetPrivate / 1mb),2)}}
)
$Processes = (Get-WmiObject -class Win32_PerfFormattedData_PerfProc_Process -ComputerName $computerName | Select-Object $properties )
Write-Host "<prtg>";
Foreach($Process in $Processes){
if( $Process.'Process Name' -notmatch $ignoreList){
Write-Host ([string]::Format($channelTemplateCPULoad, $Process.'Process Name', $Process.'CPU (%)'))
Write-Host ([string]::Format($channelTemplateMemoryUsage, $Process.'Process Name', $Process.'Memory (MB)'))
}
}
Write-Host "</prtg>";
However, filtering via $ignoreList doesn't work properly yet, you'll need to work on that (otherwise, you'll have 300 or more svchost processes). The script is provided as is and should give you a starting point. We can't help in getting it up and running as desired in your environment. Please also check our Guide for PowerShell based Custom Sensors for further installation details.
PRTG Scheduler |
PRTGapi |
Feature Requests |
WMI Issues |
SNMP Issues
Kind regards,
Stephan Linke, Tech Support Team
Add comment