Created
February 21, 2014 16:31
-
-
Save cgorshing/9137543 to your computer and use it in GitHub Desktop.
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
#Functions are first | |
#Go to the end for the 'main' of the script | |
$ErrorActionPreference = "Stop" | |
Set-PSDebug -strict | |
Set-StrictMode –Version latest | |
$source = "Mule Monitoring" | |
#New-EventLog -LogName Application -Source $source | |
#EntryType - Valid values are Error, Warning, Information, SuccessAudit, and FailureAudit. The default value is Information. | |
#-ComputerName Server01 | |
Function FindApplicationName($wc) { | |
$json = $wc.DownloadString("http://localhost:8899/jolokia/list") | ConvertFrom-Json | |
#$json = $wc.DownloadString("some-static-url-for-testing") | ConvertFrom-Json | |
foreach ($element in get-member -MemberType NoteProperty -inputobject $json.value) { | |
if ($element.name.startswith('Mule.your-application-name')) { | |
return $element.Name | |
} | |
} | |
} | |
Function CheckMuleMemoryUsed($wc) { | |
$json = $wc.DownloadString("http://localhost:8899/jolokia/read/java.lang:type=Memory/HeapMemoryUsage") | ConvertFrom-Json | |
#$json = $wc.DownloadString("some-static-url-for-testing") | ConvertFrom-Json | |
$maxMemory = $json.value.max | |
$usedMemory = $json.value.used | |
$threshold = .75 | |
$calculatedValue = $usedMemory / $maxMemory | |
IF ($calculatedValue -gt $threshold) | |
{ | |
Write-EventLog -LogName Application -Source $source -EventID 3001 -EntryType Error -Message "Mule has exceeded the memory threshold." -Category 1 -RawData 10,20 | |
} | |
ELSE | |
{ | |
#Write-Host "All looks well" | |
} | |
} | |
Function CheckMuleMinProcessingTime($wc, $applicationName) { | |
$json = $wc.DownloadString("http://localhost:8899/jolokia/read/"+ $applicationName + ":name=%22application%20totals%22,type=Application/MinProcessingTime") | ConvertFrom-Json | |
#$json = $wc.DownloadString("some-static-url-for-testing") | ConvertFrom-Json | |
$time = $json.value | |
$maximumTime = 100 | |
IF ($time -gt $maximumTime) | |
{ | |
Write-EventLog -LogName Application -Source $source -EventID 3001 -EntryType Error -Message "Mule has exceeded the minimum processing time." -Category 1 -RawData 10,20 | |
} | |
ELSE | |
{ | |
#Write-Host "All looks well" | |
} | |
} | |
Function CheckMuleMaxProcessingTime($wc, $applicationName) { | |
$json = $wc.DownloadString("http://localhost:8899/jolokia/read/"+ $applicationName + ":name=%22application%20totals%22,type=Application/MaxProcessingTime") | ConvertFrom-Json | |
#$json = $wc.DownloadString("some-static-url-for-testing") | ConvertFrom-Json | |
$time = $json.value | |
$maximumTime = 1000 | |
IF ($time -gt $maximumTime) | |
{ | |
Write-EventLog -LogName Application -Source $source -EventID 3001 -EntryType Error -Message "Mule has exceeded the maximum processing time threshold." -Category 1 -RawData 10,20 | |
} | |
ELSE | |
{ | |
#Write-Host "All looks well" | |
} | |
} | |
Function CheckMuleExecutionErrors($wc, $applicationName) { | |
$json = $wc.DownloadString("http://localhost:8899/jolokia/read/"+ $applicationName + ":name=%22application%20totals%22,type=Application/ExecutionErrors") | ConvertFrom-Json | |
#$json = $wc.DownloadString("some-static-url-for-testing") | ConvertFrom-Json | |
$executionErrors = $json.value | |
$threshold = 5 | |
IF ($executionErrors -gt $threshold) | |
{ | |
Write-EventLog -LogName Application -Source $source -EventID 3001 -EntryType Error -Message "Mule has exceeded the execution errors threshold." -Category 1 -RawData 10,20 | |
} | |
ELSE | |
{ | |
#Write-Host "All looks well" | |
} | |
} | |
Function CheckMuleAverageProcessingTime($wc, $applicationName) { | |
$json = $wc.DownloadString("http://localhost:8899/jolokia/read/"+ $applicationName + ":name=%22application%20totals%22,type=Application/AverageProcessingTime") | ConvertFrom-Json | |
#$json = $wc.DownloadString("some-static-url-for-testing") | ConvertFrom-Json | |
$time = $json.value | |
$threshold = 100 | |
IF ($time -gt $threshold) | |
{ | |
Write-EventLog -LogName Application -Source $source -EventID 3001 -EntryType Error -Message "Mule has exceeded the average processing time." -Category 1 -RawData 10,20 | |
} | |
ELSE | |
{ | |
#Write-Host "All looks well" | |
} | |
} | |
Function CheckActiveMQ($wc, $destination) { | |
$url = "http://localhost:8161/api/jolokia/read/org.apache.activemq:brokerName=$brokerName,destinationName=$destination,destinationType=Queue,type=Broker/QueueSize" | |
$json = $wc.DownloadString($url) | ConvertFrom-Json | |
$count = $json.value | |
$threshold = 100 | |
IF ($count -gt $threshold) | |
{ | |
Write-EventLog -LogName Application -Source $source -EventID 3001 -EntryType Error -Message "ActiveMQ has exceeded the queue size for $destination." -Category 1 -RawData 10,20 | |
} | |
ELSE | |
{ | |
#Write-Host "All looks well" | |
} | |
} | |
$wc = New-Object System.Net.WebClient; | |
$applicationName = FindApplicationName($wc) | |
CheckMuleMemoryUsed $wc | |
CheckMuleMinProcessingTime $wc $applicationName | |
CheckMuleMaxProcessingTime $wc $applicationName | |
CheckMuleExecutionErrors $wc $applicationName | |
CheckMuleAverageProcessingTime $wc $applicationName | |
# Set up credentials to use for ActiveMQ | |
$credCache = new-object System.Net.CredentialCache | |
$activemqCreds = new-object System.Net.NetworkCredential('<username>','<password>') | |
$credCache.Add('http://localhost:8161', 'Basic', $activemqCreds) | |
$wc.Credentials = $credCache | |
# Set ActiveMQ brokre name | |
$activemqBroker = 'jms-env-1' | |
CheckActiveMQ $wc 'Queue.Name.1' | |
CheckActiveMQ $wc 'Queue.Name.2' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment