Last active
August 15, 2018 08:22
-
-
Save stephanlinke/0ccd28a0b6322f98a5b986ba65df6938 to your computer and use it in GitHub Desktop.
It will basically do the same/retrieve the same metrics as the IIS App Pool sensor, but using a powershell script to do so. Here's what to do to get the custom sensor running. Installation details can be found at https://kb.paessler.com/en/topic/73440
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#parameters to set in exexml sensor: -target '%host' -instance 'name_of_instance' | |
param( | |
[string]$target = '10.0.0.133', | |
[string]$instance = 'SharePoint - 80' | |
) | |
$DataTable = New-Object System.Data.DataTable | |
$name = New-Object System.Data.DataColumn ‘name’,([String]) | |
$query = New-Object System.Data.DataColumn ‘query’,([String]) | |
$result = New-Object System.Data.DataColumn ‘result’,([String]) | |
$DataTable.Columns.Add($name) | |
$DataTable.Columns.Add($query) | |
$DataTable.Columns.Add($result) | |
[void]$DataTable.Rows.Add("Current Application Pool State","\APP_POOL_WAS($($instance))\Current Application Pool State","") | |
[void]$DataTable.Rows.Add("Current Worker Processes","\APP_POOL_WAS($($instance))\Current Worker Processes","") | |
[void]$DataTable.Rows.Add("Total Worker Process Failures","\APP_POOL_WAS($($instance))\Total Worker Process Failures","") | |
[void]$DataTable.Rows.Add("Total Worker Process Ping Failures","\APP_POOL_WAS($($instance))\Total Worker Process Ping Failures","") | |
[void]$DataTable.Rows.Add("Total Worker Process Shutdown Failures","\APP_POOL_WAS($($instance))\Total Worker Process Shutdown Failures","") | |
[void]$DataTable.Rows.Add("Total Worker Process Startup Failures","\APP_POOL_WAS($($instance))\Total Worker Process Startup Failures","") | |
$exectime = [System.Diagnostics.Stopwatch]::StartNew() | |
foreach($entry in $DataTable) { | |
try { | |
$a = Get-Counter -ComputerName $target -Counter $entry.query -ErrorAction Stop | |
}catch{ | |
Write-Output "<prtg>" | |
Write-Output "<error>1</error>" | |
Write-Output "<text>Query Failed: $($_.Exception.Message)</text>" | |
Write-Output "</prtg>" | |
Exit | |
} | |
$entry.result = [math]::Round($a.CounterSamples.CookedValue,0) | |
} | |
$exectime.Stop() | |
Write-Output "<prtg>" | |
foreach($entry in $DataTable){ | |
Write-Output "<result>" | |
Write-Output "<channel>$($entry.name)</channel>" | |
Write-Output "<value>$($entry.result)</value>" | |
Write-Output "</result>" | |
} | |
Write-Output "<result>" | |
Write-Output "<channel>ExecTime</channel>" | |
Write-Output "<value>$($exectime.ElapsedMilliseconds)</value>" | |
Write-Output "<CustomUnit>msecs</CustomUnit>" | |
Write-Output "</result>" | |
Write-Output "</prtg>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment