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

update example script to test for miniredis size

Changeset 266caa08a0ea

Parent 3ac204ef9f66

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

Changes to 2 files · Browse files at 266caa08a0ea Showing diff from parent 3ac204ef9f66 Diff from another changeset...

Change 1 of 3 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
 
70
71
72
73
74
 
75
76
77
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
 
69
70
71
72
73
 
74
75
76
77
 $g_backendUrl = "http://localhost:56783/"  $g_kilnRepositories = "C:\KilnRepositories"    function Get-URL([string] $url){   (New-Object net.webclient).DownloadString($url)  }    function LogOrWrite($msg, $logFile = ""){   if ($logFile -ne "") { - write $msg | out-file -append $logFile + write "$(Get-Date -format o) $msg" | out-file -append $logFile   }   else {   write $msg   }  }    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){ +function Get-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 + LogOrWrite "The service $service has $($measure.Count) instances with a total WorkingSet of: $($measure.Sum)" $logFile   }   catch { - write "$(Get-Date -format o) The service $service is not currently running." | out-file -append $logFile + LogOrWrite "The service $service is not currently running." $logFile   }  }    function Get-MiniRedisSize([string] $kilnRepositoriesDir = $g_kilnrepositories, [string] $logFile = ""){   try {   $kilnRepo = (Resolve-Path $kilnRepositoriesDir -ErrorAction Stop).path   }   catch {   LogOrWrite "Could not find Kiln Repositories Directory: $kilnRepositoriesDir" $logFile   }   try {   $miniRedis = (Resolve-Path ($kilnRepo + "\miniredis.db") -ErrorAction Stop).path   }   catch {   LogOrWrite "Could not find miniredis.db file in $kilnRepo" $logFile   }   $lenMiniRedis = (get-childitem -path $miniRedis).length   LogOrWrite "The size of miniredis.db is: $lenMiniRedis" $logFile   return $lenMiniRedis  }    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 - LogOrWrite "$(Get-Date -format o) Something is wrong. Restarting Kiln Storage Service" $logFile + LogOrWrite "Something is wrong. Restarting Kiln Storage Service" $logFile   Restart-Service "KilnStorageService"   return $False   }   else { - LogOrWrite "$(Get-Date -format o) Kiln backend is OK" $logFile + LogOrWrite "Kiln backend is OK" $logFile   return $True   }  }
 
3
4
5
 
6
7
8
 
9
10
11
12
13
 
 
 
 
14
15
16
 
 
 
 
 
 
 
 
17
 
 
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
 
@@ -3,15 +3,25 @@
 $sChangeset1 = 'f181ad06356697b8676868fec36fbe13167081dd'  $sChangeset2 = 'ed5f14291c3ab9d9bf24dee8e1b4761799509d15'  $logFile = "C:\code\checkKiln\checkBackend.log" +$kilnRepositories = "C:\KilnRepositories"  $smtpServer = "testmail.example.com"  $from = "ben@example.com"  $to = "ben@example.com" +$maxMiniRedisSize = 3000000 #3MB   -Log-ServiceStats "backend" $logFile -Log-ServiceStats "memcached" $logFile -Log-ServiceStats "QueueService" $logFile -Log-ServiceStats "redis-server" $logFile +Get-ServiceStats "backend" $logFile +Get-ServiceStats "memcached" $logFile +Get-ServiceStats "QueueService" $logFile +Get-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" #-Attachment $logFile +} +$lenMiniRedis = Get-MiniRedisSize $kilnRepositories $logFile +$intLenMiniRedis = 0 +if ([System.Int64]::TryParse($lenMiniRedis, [ref]$intLenMiniRedis)) { + if ($intLenMiniRedis -gt $maxMiniRedisSize) { + $strLenMiniRedisKb = "{0:N0}" -f ($intLenMiniRedis / 1024) + Send-MailMessage -From $from -To $to -SmtpServer $SmtpServer -Subject "The Kiln MiniRedis.db is too large" -Body "MiniRedis.db is $strLenMiniRedisKB KB" + }  } \ No newline at end of file