Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/100-General/10-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
* [#480](https://github.com/Icinga/icinga-powershell-framework/pull/480) Fixes service locking during Icinga Agent upgrade and ensures errors on service management are caught and printed with internal error handling
* [#483](https://github.com/Icinga/icinga-powershell-framework/issues/483) Fixes REST-Api SSL certificate lookup from the Icinga Agent, in case a custom hostname was used or in certain domain environments were domain is not matching DNS domain
* [#490](https://github.com/Icinga/icinga-powershell-framework/pull/490) Fixes the command `Uninstall-IcingaComponent` for the `service` component which is not doing anything
* [#491](https://github.com/Icinga/icinga-powershell-framework/issues/491) Fixes GC collection with `Optimize-IcingaForWindowsMemory` for every incoming REST connection call
* [#497](https://github.com/Icinga/icinga-powershell-framework/pull/497) Fixes loop sleep for idle REST-Api threads by replacing them with [BlockingCollection](https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent.blockingcollection-1?view=net-6.0) [ConcurrentQueue](https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent.concurrentqueue-1?view=net-6.0)

### Enhancements
Expand Down
1 change: 1 addition & 0 deletions lib/core/framework/New-IcingaEnvironmentVariable.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ function New-IcingaEnvironmentVariable()
$Global:Icinga.Protected.Add('RunAsDaemon', $FALSE);
$Global:Icinga.Protected.Add('Minimal', $FALSE);
$Global:Icinga.Protected.Add('ThreadName', '');
$Global:Icinga.Protected.Add('GarbageCollector', @{ });
}
}
23 changes: 22 additions & 1 deletion lib/core/tools/Optimize-IcingaForWindowsMemory.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
properly
.PARAMETER ClearErrorStack
Also clears the current error stack to free additional memory
.PARAMETER SmartGC
Ensures that memory is not flushed whenever this function is called, but instead
every 30 attempts this function is called to reduce CPU load. Only works for
PowerShell sessions with "$Global:Icinga.Protected.ThreadName" being set
.EXAMPLE
Optimize-IcingaForWindowsMemory;
.EXAMPLE
Expand All @@ -21,9 +25,26 @@
function Optimize-IcingaForWindowsMemory()
{
param (
[switch]$ClearErrorStack = $FALSE
[switch]$ClearErrorStack = $FALSE,
[switch]$SmartGC = $FALSE
);

if ([string]::IsNullOrEmpty($Global:Icinga.Protected.ThreadName) -eq $FALSE -And $SmartGC) {
if ($Global:Icinga.Protected.GarbageCollector.ContainsKey($Global:Icinga.Protected.ThreadName) -eq $FALSE) {
$Global:Icinga.Protected.GarbageCollector.Add($Global:Icinga.Protected.ThreadName, 0);

return;
} else {
$Global:Icinga.Protected.GarbageCollector[$Global:Icinga.Protected.ThreadName] += 1;
}

if ($Global:Icinga.Protected.GarbageCollector[$Global:Icinga.Protected.ThreadName] -le 30) {
return;
}

$Global:Icinga.Protected.GarbageCollector[$Global:Icinga.Protected.ThreadName] = 0;
}

# Clear all errors within our error stack
if ($ClearErrorStack) {
$Error.Clear();
Expand Down
5 changes: 4 additions & 1 deletion lib/daemon/Add-IcingaForWindowsDaemon.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ function Add-IcingaForWindowsDaemon()
}

while ($TRUE) {
Start-Sleep -Seconds 1;
Start-Sleep -Seconds 10;

# Handle possible threads being frozen
Suspend-IcingaForWindowsFrozenThreads;

# Force Icinga for Windows Garbage Collection
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function New-IcingaForWindowsRESTApi()
while ($TRUE) {

# Force Icinga for Windows Garbage Collection
Optimize-IcingaForWindowsMemory -ClearErrorStack;
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;

$Connection = Open-IcingaTCPClientConnection `
-Client (New-IcingaTCPClient -Socket $Socket) `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,6 @@ function New-IcingaForWindowsRESTThread()
Close-IcingaTCPConnection -Client $Connection.Client;

# Force Icinga for Windows Garbage Collection
Optimize-IcingaForWindowsMemory -ClearErrorStack;
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ function Add-IcingaServiceCheckDaemon()
}
}

Optimize-IcingaForWindowsMemory;
# Force Icinga for Windows Garbage Collection
Optimize-IcingaForWindowsMemory -SmartGC;

Start-Sleep -Seconds 10;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function Add-IcingaServiceCheckTask()
Clear-IcingaCheckSchedulerEnvironment;

# Force Icinga for Windows Garbage Collection
Optimize-IcingaForWindowsMemory -ClearErrorStack;
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;

continue;
}
Expand Down Expand Up @@ -133,6 +133,6 @@ function Add-IcingaServiceCheckTask()
# Reset certain values from the scheduler environment
Clear-IcingaServiceCheckDaemonEnvironment;
# Force Icinga for Windows Garbage Collection
Optimize-IcingaForWindowsMemory -ClearErrorStack;
Optimize-IcingaForWindowsMemory -ClearErrorStack -SmartGC;
}
}