mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
Fixes Service Check Background Daemon Memory leak
Fixes #20 This fixes the memory leak on the Service Check Background Daemon, mainly caused by not properly catching the boolean return values of `Add-IcingaHashtableItem`. The boolean values stayed within the scope, poluting the memory and causing functions to behave not as expected
This commit is contained in:
parent
06b7c0cdd5
commit
9df17e1068
2 changed files with 16 additions and 13 deletions
|
|
@ -16,7 +16,8 @@ function Add-IcingaHashtableItem()
|
||||||
return $TRUE;
|
return $TRUE;
|
||||||
} else {
|
} else {
|
||||||
if ($Override) {
|
if ($Override) {
|
||||||
$Hashtable[$Key] = $Value;
|
$Hashtable.Remove($Key);
|
||||||
|
$Hashtable.Add($Key, $Value);
|
||||||
return $TRUE;
|
return $TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -79,9 +79,10 @@ function Start-IcingaServiceCheckTask()
|
||||||
$UnixTime = Get-IcingaUnixTime;
|
$UnixTime = Get-IcingaUnixTime;
|
||||||
|
|
||||||
foreach ($result in $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'].Keys) {
|
foreach ($result in $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'].Keys) {
|
||||||
$SortedResult = $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'][$result].GetEnumerator() | Sort-Object name -Descending;
|
[string]$HashIndex = $result;
|
||||||
Add-IcingaHashtableItem -Hashtable $OldData -Key $result -Value @{};
|
$SortedResult = $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['results'][$HashIndex].GetEnumerator() | Sort-Object name -Descending;
|
||||||
Add-IcingaHashtableItem -Hashtable $PerfCache -Key ([string]$result) -Value @{};
|
Add-IcingaHashtableItem -Hashtable $OldData -Key $HashIndex -Value @{} | Out-Null;
|
||||||
|
Add-IcingaHashtableItem -Hashtable $PerfCache -Key $HashIndex -Value @{} | Out-Null;
|
||||||
|
|
||||||
foreach ($index in $TimeIndexes) {
|
foreach ($index in $TimeIndexes) {
|
||||||
$ObjectCount = 0;
|
$ObjectCount = 0;
|
||||||
|
|
@ -92,19 +93,20 @@ function Start-IcingaServiceCheckTask()
|
||||||
if (($UnixTime - $TimeInSeconds) -le [int]$timeEntry.Key) {
|
if (($UnixTime - $TimeInSeconds) -le [int]$timeEntry.Key) {
|
||||||
$ObjectCount += 1;
|
$ObjectCount += 1;
|
||||||
$ObjectValue += $timeEntry.Value;
|
$ObjectValue += $timeEntry.Value;
|
||||||
Remove-IcingaHashtableItem -Hashtable $OldData[$result] -Key $timeEntry;
|
Remove-IcingaHashtableItem -Hashtable $OldData[$HashIndex] -Key $timeEntry;
|
||||||
Add-IcingaHashtableItem -Hashtable $PerfCache[$result] -Key ([string]$timeEntry.Key) -Value ([string]$timeEntry.Value);
|
Add-IcingaHashtableItem -Hashtable $PerfCache[$HashIndex] -Key ([string]$timeEntry.Key) -Value ([string]$timeEntry.Value) | Out-Null;
|
||||||
} else {
|
} else {
|
||||||
Add-IcingaHashtableItem -Hashtable $OldData[$result] -Key $timeEntry -Value $null;
|
Add-IcingaHashtableItem -Hashtable $OldData[$HashIndex] -Key $timeEntry -Value $null | Out-Null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$AvarageValue = ($ObjectValue / $ObjectCount);
|
$AverageValue = ($ObjectValue / $ObjectCount);
|
||||||
$MetricName = [string]::Format('{0}_{1}', $result, $index);
|
[string]$MetricName = [string]::Format('{0}_{1}', $HashIndex, $index);
|
||||||
|
$MetricName = Format-IcingaPerfDataLabel $MetricName;
|
||||||
|
|
||||||
Add-IcingaHashtableItem `
|
Add-IcingaHashtableItem `
|
||||||
-Hashtable $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['average'] `
|
-Hashtable $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['average'] `
|
||||||
-Key (Format-IcingaPerfDataLabel $MetricName) -Value $AvarageValue -Override;
|
-Key $MetricName -Value $AverageValue -Override | Out-Null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,9 +125,9 @@ function Start-IcingaServiceCheckTask()
|
||||||
}
|
}
|
||||||
|
|
||||||
$PassedTime = 0;
|
$PassedTime = 0;
|
||||||
$SortedResult = $null;
|
$SortedResult.Clear();
|
||||||
$OldData = @{};
|
$OldData.Clear();
|
||||||
$PerfCache = @{};
|
$PerfCache.Clear();
|
||||||
}
|
}
|
||||||
$PassedTime += 1;
|
$PassedTime += 1;
|
||||||
Start-Sleep -Seconds 1;
|
Start-Sleep -Seconds 1;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue