-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #206 from Icinga:fix/background_service_checks_not…
…_working Fix: Background service check daemon data pool separation and memory leak Improves the background daemon by separating each single configured check into an own data pool, preventing data of leaking from one thread to another which might cause a memory leak in long term with plenty of background checks defined. This might also reduce CPU impact because lesser data has to be processed.
- Loading branch information
Showing
9 changed files
with
171 additions
and
36 deletions.
There are no files selected for viewing
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
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
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
28 changes: 28 additions & 0 deletions
28
lib/core/framework/Clear-IcingaCheckSchedulerCheckData.psm1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<# | ||
.SYNOPSIS | ||
Clear all cached values for all check commands executed by this thread. | ||
This is mandatory as we might run into a memory leak otherwise! | ||
.DESCRIPTION | ||
Clear all cached values for all check commands executed by this thread. | ||
This is mandatory as we might run into a memory leak otherwise! | ||
.FUNCTIONALITY | ||
Clear all cached values for all check commands executed by this thread. | ||
This is mandatory as we might run into a memory leak otherwise! | ||
.OUTPUTS | ||
System.Object | ||
.LINK | ||
https://github.com/Icinga/icinga-powershell-framework | ||
#> | ||
|
||
function Clear-IcingaCheckSchedulerCheckData() | ||
{ | ||
if ($null -eq $global:Icinga) { | ||
return; | ||
} | ||
|
||
if ($global:Icinga.ContainsKey('CheckData') -eq $FALSE) { | ||
return; | ||
} | ||
|
||
$global:Icinga.CheckData.Clear(); | ||
} |
26 changes: 26 additions & 0 deletions
26
lib/core/framework/Clear-IcingaCheckSchedulerEnvironment.psm1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<# | ||
.SYNOPSIS | ||
Clears the entire check scheduler cache environment and frees memory as | ||
well as cleaning the stack | ||
.DESCRIPTION | ||
Clears the entire check scheduler cache environment and frees memory as | ||
well as cleaning the stack | ||
.FUNCTIONALITY | ||
Clears the entire check scheduler cache environment and frees memory as | ||
well as cleaning the stack | ||
.OUTPUTS | ||
System.Object | ||
.LINK | ||
https://github.com/Icinga/icinga-powershell-framework | ||
#> | ||
|
||
function Clear-IcingaCheckSchedulerEnvironment() | ||
{ | ||
if ($null -eq $global:Icinga) { | ||
return; | ||
} | ||
|
||
Get-IcingaCheckSchedulerPluginOutput | Out-Null; | ||
Get-IcingaCheckSchedulerPerfData | Out-Null; | ||
Clear-IcingaCheckSchedulerCheckData; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<# | ||
.SYNOPSIS | ||
Fetch the raw output values for a check command for each single object | ||
processed by New-IcingaCheck | ||
.DESCRIPTION | ||
Fetch the raw output values for a check command for each single object | ||
processed by New-IcingaCheck | ||
.FUNCTIONALITY | ||
Fetch the raw output values for a check command for each single object | ||
processed by New-IcingaCheck | ||
.OUTPUTS | ||
System.Object | ||
.LINK | ||
https://github.com/Icinga/icinga-powershell-framework | ||
#> | ||
|
||
function Get-IcingaCheckSchedulerCheckData() | ||
{ | ||
if ($null -eq $global:Icinga) { | ||
return $null; | ||
} | ||
|
||
if ($global:Icinga.ContainsKey('CheckData') -eq $FALSE) { | ||
return @{ }; | ||
} | ||
|
||
return $global:Icinga.CheckData; | ||
} |
56 changes: 52 additions & 4 deletions
56
lib/core/framework/New-IcingaCheckSchedulerEnvironment.psm1
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,60 @@ | ||
<# | ||
.SYNOPSIS | ||
Create a new environment in which we can store check results, performance data | ||
and values over time or executed plugins. | ||
Usage: | ||
Access the string plugin output by calling `Get-IcingaCheckSchedulerPluginOutput` | ||
Access possible performance data with `Get-IcingaCheckSchedulerPerfData` | ||
If you execute check plugins, ensure you read both of these functions to fetch the | ||
result of the plugin call and to clear the stack and memory of the check data. | ||
If you do not require the output, you can write them to Null | ||
Get-IcingaCheckSchedulerPluginOutput | Out-Null; | ||
Get-IcingaCheckSchedulerPerfData | Out-Null; | ||
IMPORTANT: | ||
In addition each value for each object created with `New-IcingaCheck` is stored | ||
with a timestamp for the check command inside a hashtable. If you do not require | ||
these data, you MUST call `Clear-IcingaCheckSchedulerCheckData` to free memory | ||
and clear data from the stack! | ||
If you are finished with all data processing and do not require anything within | ||
memory anyway, you can safely call `Clear-IcingaCheckSchedulerEnvironment` to | ||
do the same thing in one call. | ||
.DESCRIPTION | ||
Fetch the raw output values for a check command for each single object | ||
processed by New-IcingaCheck | ||
.FUNCTIONALITY | ||
Fetch the raw output values for a check command for each single object | ||
processed by New-IcingaCheck | ||
.OUTPUTS | ||
System.Object | ||
.LINK | ||
https://github.com/Icinga/icinga-powershell-framework | ||
#> | ||
|
||
function New-IcingaCheckSchedulerEnvironment() | ||
{ | ||
# Legacy code | ||
$IcingaDaemonData.IcingaThreadContent.Add('Scheduler', @{ }); | ||
if ($IcingaDaemonData.IcingaThreadContent.ContainsKey('Scheduler') -eq $FALSE) { | ||
$IcingaDaemonData.IcingaThreadContent.Add('Scheduler', @{ }); | ||
} | ||
|
||
if ($null -eq $global:Icinga) { | ||
$global:Icinga = @{}; | ||
$global:Icinga = @{ }; | ||
} | ||
|
||
$global:Icinga.Add('CheckResults', @()); | ||
$global:Icinga.Add('PerfData', @()); | ||
if ($global:Icinga.ContainsKey('CheckResults') -eq $FALSE) { | ||
$global:Icinga.Add('CheckResults', @()); | ||
} | ||
if ($global:Icinga.ContainsKey('PerfData') -eq $FALSE) { | ||
$global:Icinga.Add('PerfData', @()); | ||
} | ||
if ($global:Icinga.ContainsKey('CheckData') -eq $FALSE) { | ||
$global:Icinga.Add('CheckData', @{ }); | ||
} | ||
} |
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
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