Kiln » KilnSupportScripts Powershell Scripts to help monitor a Kiln environment. Contact Fog Creek support before using.
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

renamed run-checkBackend to be an example file

Changeset 6f710dfcbe3c

Parent e03a60de87a6

by Profile picture of User 476Ben McCormack <benm@fogcreek.com>

Changes to 3 files · Browse files at 6f710dfcbe3c Showing diff from parent e03a60de87a6 Diff from another changeset...

Change 1 of 1 Show Changes Only checkBackend.ps1 Stacked
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 
39
40
41
 
42
43
44
45
46
 
47
48
49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 
38
39
40
 
41
42
43
44
45
 
46
47
48
49
 function Get-URL([string] $url){   (New-Object net.webclient).DownloadString($url)  }    $g_backendUrl = "http://localhost:56783/"    function Test-KilnVersion(){   try {   $resp = Get-Url(($g_backendUrl + "version"))   return ($resp.length -gt 0)   }   catch {   return $False   }  }    function Test-KilnDiff([string] $sRepoGUID, [string] $sChangeset1, [string] $sChangeset2){   try {   $url =$g_backendUrl + "repo/" + $sRepoGUID + "/diff/" + $sChangeset1 + ":" + $sChangeset2 + "?format=json&ignorews=True&maxsize=100000&timeout=10"   $resp = Get-Url($url)   return ($resp.length -gt 0)   }   catch {   return $False   }  }    function Log-ServiceStats([string] $service, [string] $logFile){   try {   $measure = get-process $service -ErrorAction Stop | Measure-Object WorkingSet -sum   write "$(Get-Date -format o) The service $service has $($measure.Count) instances with a total WorkingSet of: $($measure.Sum)" | out-file -append $logFile   }   catch {   write "$(Get-Date -format o) The service $service is not currently running." | out-file -append $logFile   }  }   -function Check-KilnBackend([string] $sRepoGUID, [string] $sChangeset1, [string] $sChangeset2, [string] $logFile){ +function Check-KilnBackend([string] $sRepoGUID, [string] $sChangeset1, [string] $sChangeset2, [string] $logFile = ""){   if (-Not ((Test-KilnVersion) -and (Test-KilnDiff $sRepoGUID $sChangeset1 $sChangeset2))){   #Restart the Kiln storage Service because something bad happened - write "$(Get-Date -format o) Something is wrong. Restarting Kiln Storage Service" | out-file -append $logFile + write "$(Get-Date -format o) Something is wrong. Restarting Kiln Storage Service" | foreach{if ($logFile -ne "") {out-file -append $logFile} else {out-default}}   Restart-Service "KilnStorageService"   return $False   }   else { - write "$(Get-Date -format o) Kiln backend is OK" | out-file -append $logFile + write "$(Get-Date -format o) Kiln backend is OK" | foreach{if ($logFile -ne "") {$_ | out-file -append $logFile} else {$_ | out-default}}   return $True   }  }
Change 1 of 1 Show Entire File run-checkBackend.example.ps1 Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
@@ -0,0 +1,17 @@
+. C:\code\checkKiln\checkBackend.ps1 +$sRepoGUID = 'B530EC64-82BE-473A-82E1-569464B1074A' +$sChangeset1 = 'f181ad06356697b8676868fec36fbe13167081dd' +$sChangeset2 = 'ed5f14291c3ab9d9bf24dee8e1b4761799509d15' +$logFile = "C:\code\checkKiln\checkBackend.log" +$smtpServer = "testmail.example.com" +$from = "ben@example.com" +$to = "ben@example.com" + +Log-ServiceStats "backend" $logFile +Log-ServiceStats "memcached" $logFile +Log-ServiceStats "QueueService" $logFile +Log-ServiceStats "redis-server" $logFile +$passed = Check-KilnBackend $sRepoGUID $sChangeset1 $sChangeset2 $logFile +if (-not $passed) { + Send-MailMessage -From $from -To $to -SmtpServer $SmtpServer -Subject "The Kiln Backend Had To Be Restarted" +} \ No newline at end of file
Change 1 of 1 Show Entire File run-checkBackend.ps1 Stacked
 
1
2
3
4
5
6
7
8
9
10
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,11 +0,0 @@
-. C:\code\checkKiln\checkBackend.ps1 -$sRepoGUID = 'B530EC64-82BE-473A-82E1-569464B1074A' -$sChangeset1 = 'f181ad06356697b8676868fec36fbe13167081dd' -$sChangeset2 = 'ed5f14291c3ab9d9bf24dee8e1b4761799509d15' -$logFile = "C:\code\checkKiln\checkBackend.log" - -Log-ServiceStats "backend" $logFile -Log-ServiceStats "memcached" $logFile -Log-ServiceStats "QueueService" $logFile -Log-ServiceStats "redis-server" $logFile -Check-KilnBackend $sRepoGUID $sChangeset1 $sChangeset2 $logFile \ No newline at end of file