Skip to content

Instantly share code, notes, and snippets.

@stephanlinke
Created November 19, 2018 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephanlinke/6b3e9cb001755a9fb4a77c182ebd0f70 to your computer and use it in GitHub Desktop.
Save stephanlinke/6b3e9cb001755a9fb4a77c182ebd0f70 to your computer and use it in GitHub Desktop.
#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