#-----------------------------------------------------------------------------
# This script will check that Kiln is running and healthy by hitting a variety of HTTP endpoints
#
# Usage example:
# ./Monitor-Kiln.ps1 -kilnURL "http://localhost/fogbugz/kiln"
#
#-----------------------------------------------------------------------------
param([string]$kilnURL = "http://localhost/fogbugz/kiln",
[string]$backendVersionUrl = "http://localhost:56783/version",
[string]$EsUrl = "http://localhost:9200/",
[string]$QueueStatsUrl = "http://localhost:56785/stats.json")
function Write-WithTime($msg){
write "$(Get-Date -format o) $msg"
}
function Test-ProcessRunning($processName, $count = 1)
{
Write-WithTime "Checking that $count instance(s) of $processName are running..."
$result = (Get-Process $processName -ea SilentlyContinue | select id | measure).count -ge $count
if ($result) { Write-WithTime "Success!" }
else { Write-WithTime "FAILURE!" }
}
function Test-ElasticSearchRunning()
{
Write-WithTime "Checking that 1 instances(s) of ElasticSearch are running..."
$result = (Get-WmiObject win32_process -Filter "name like 'java.exe'" | select commandline | select-string "ElasticSearch" | measure).count -eq 1
if ($result) { Write-WithTime "Success!" }
else { Write-WithTime "FAILURE!" }
}
function Test-HttpResponse($url, $searchString)
{
Write-WithTime "Checking for expected response from URL ($url)..."
try
{
$response = (New-Object net.webclient).DownloadString($url)
$response = (New-Object net.webclient).DownloadString($url)
$result = $response | select-string $searchString
if ($result) { Write-WithTime "Success!" }
else { Write-WithTime "FAILURE!" }
}
catch [Net.WebException]
{
Write-WithTime $_.Exception.ToString()
}
}
Test-ProcessRunning "backend"
Test-ProcessRunning "redis-server" 2
Test-ProcessRunning "QueueService"
Test-ElasticSearchRunning
Test-HttpResponse $kilnURL "Log on to Kiln"
Test-HttpResponse $backendVersionUrl '"hg_version"'
Test-HttpResponse $EsUrl '"status" : 200'
Test-HttpResponse $QueueStatsUrl '"queueName":"Kiln"'
# TODO: Parse the QueueStats data and alert when poor behavior is detected. Attempt automatic restart?
|
Loading...