mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-20 23:00:35 -05:00
parent
0d6a68ffee
commit
c6e9da9783
1 changed files with 44 additions and 16 deletions
|
|
@ -47,6 +47,31 @@ function Start-IcingaServiceCheckTask()
|
||||||
$SortedResult = $null;
|
$SortedResult = $null;
|
||||||
$OldData = @{};
|
$OldData = @{};
|
||||||
$PerfCache = @{};
|
$PerfCache = @{};
|
||||||
|
$AverageCalc = @{};
|
||||||
|
[int]$MaxTime = 0;
|
||||||
|
|
||||||
|
foreach ($index in $TimeIndexes) {
|
||||||
|
# Only allow numeric index values
|
||||||
|
if ((Test-Numeric $index) -eq $FALSE) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($AverageCalc.ContainsKey([string]$index) -eq $FALSE) {
|
||||||
|
$AverageCalc.Add(
|
||||||
|
[string]$index,
|
||||||
|
@{
|
||||||
|
'Interval' = [int]$index;
|
||||||
|
'Time' = [int]$index * 60;
|
||||||
|
'Sum' = 0;
|
||||||
|
'Count' = 0;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if ($MaxTime -le [int]$index) {
|
||||||
|
$MaxTime = [int]$index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[int]$MaxTimeInSeconds = $MaxTime * 60;
|
||||||
|
|
||||||
if (-Not ($IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.ContainsKey($CheckCommand))) {
|
if (-Not ($IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.ContainsKey($CheckCommand))) {
|
||||||
$IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.Add($CheckCommand, [hashtable]::Synchronized(@{}));
|
$IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler.Add($CheckCommand, [hashtable]::Synchronized(@{}));
|
||||||
|
|
@ -84,29 +109,32 @@ function Start-IcingaServiceCheckTask()
|
||||||
Add-IcingaHashtableItem -Hashtable $OldData -Key $HashIndex -Value @{} | Out-Null;
|
Add-IcingaHashtableItem -Hashtable $OldData -Key $HashIndex -Value @{} | Out-Null;
|
||||||
Add-IcingaHashtableItem -Hashtable $PerfCache -Key $HashIndex -Value @{} | Out-Null;
|
Add-IcingaHashtableItem -Hashtable $PerfCache -Key $HashIndex -Value @{} | Out-Null;
|
||||||
|
|
||||||
foreach ($index in $TimeIndexes) {
|
foreach ($timeEntry in $SortedResult) {
|
||||||
$ObjectCount = 0;
|
foreach ($calc in $AverageCalc.Keys) {
|
||||||
$ObjectValue = 0;
|
if (($UnixTime - $AverageCalc[$calc].Time) -le [int]$timeEntry.Key) {
|
||||||
$TimeInSeconds = $index * 60;
|
$AverageCalc[$calc].Sum += $timeEntry.Value;
|
||||||
|
$AverageCalc[$calc].Count += 1;
|
||||||
foreach ($timeEntry in $SortedResult) {
|
|
||||||
if (($UnixTime - $TimeInSeconds) -le [int]$timeEntry.Key) {
|
|
||||||
$ObjectCount += 1;
|
|
||||||
$ObjectValue += $timeEntry.Value;
|
|
||||||
Remove-IcingaHashtableItem -Hashtable $OldData[$HashIndex] -Key $timeEntry;
|
|
||||||
Add-IcingaHashtableItem -Hashtable $PerfCache[$HashIndex] -Key ([string]$timeEntry.Key) -Value ([string]$timeEntry.Value) | Out-Null;
|
|
||||||
} else {
|
|
||||||
Add-IcingaHashtableItem -Hashtable $OldData[$HashIndex] -Key $timeEntry -Value $null | Out-Null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (($UnixTime - $MaxTimeInSeconds) -le [int]$timeEntry.Key) {
|
||||||
|
Add-IcingaHashtableItem -Hashtable $PerfCache[$HashIndex] -Key ([string]$timeEntry.Key) -Value ([string]$timeEntry.Value) | Out-Null;
|
||||||
|
} else {
|
||||||
|
Add-IcingaHashtableItem -Hashtable $OldData[$HashIndex] -Key $timeEntry -Value $null | Out-Null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$AverageValue = ($ObjectValue / $ObjectCount);
|
foreach ($calc in $AverageCalc.Keys) {
|
||||||
[string]$MetricName = [string]::Format('{0}_{1}', $HashIndex, $index);
|
$AverageValue = ($AverageCalc[$calc].Sum / $AverageCalc[$calc].Count);
|
||||||
$MetricName = Format-IcingaPerfDataLabel $MetricName;
|
[string]$MetricName = Format-IcingaPerfDataLabel (
|
||||||
|
[string]::Format('{0}_{1}', $HashIndex, $AverageCalc[$calc].Interval)
|
||||||
|
);
|
||||||
|
|
||||||
Add-IcingaHashtableItem `
|
Add-IcingaHashtableItem `
|
||||||
-Hashtable $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['average'] `
|
-Hashtable $IcingaDaemonData.BackgroundDaemon.ServiceCheckScheduler[$CheckCommand]['average'] `
|
||||||
-Key $MetricName -Value $AverageValue -Override | Out-Null;
|
-Key $MetricName -Value $AverageValue -Override | Out-Null;
|
||||||
|
|
||||||
|
$AverageCalc[$calc].Sum = 0;
|
||||||
|
$AverageCalc[$calc].Count = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue