Changes to Memory Check to support GB and Percentage

This commit is contained in:
Alexander Stoll 2019-10-30 08:37:24 +01:00
parent 73b761a4dc
commit 0d3178a51f
2 changed files with 24 additions and 27 deletions

View file

@ -40,24 +40,27 @@ function Invoke-IcingaCheckMemory()
param( param(
$Critical = $null, $Critical = $null,
$Warning = $null, $Warning = $null,
$CriticalPercent = $null,
$WarningPercent = $null,
[switch]$PageFile, [switch]$PageFile,
[ValidateSet(0, 1, 2, 3)] [ValidateSet(0, 1, 2, 3)]
[int]$Verbosity = 0 [int]$Verbosity = 0
); );
if ($PageFile -eq $TRUE) { $MemoryPackage = New-IcingaCheckPackage -Name 'Memory Usage' -OperatorAnd -Verbos $Verbosity;
$MemoryData = (Get-IcingaPageFilePerformanceCounter).'(*)\% usage'.'\Paging File(_Total)\% usage'.value $MemoryData = (Get-IcingaMemoryPerformanceCounterFormated);
} else {
$MemoryData = (Get-IcingaMemoryPerformanceCounter).'% committed bytes in use'.value;
}
$MemoryCheck = New-IcingaCheck -Name '% Memory Check' -Value $MemoryData -NoPerfData;
$MemoryCheck.WarnOutOfRange( $MemoryPerc = New-IcingaCheck -Name 'Memory Percent' -Value $MemoryData.'Memory %' -NoPerfData;
($Warning) $MemoryByte = New-IcingaCheck -Name 'Memory GigaByte' -Value $MemoryData.'Memory GigaByte' -NoPerfData;
).CritOutOfRange( $PageFile = New-IcingaCheck -Name 'PageFile Percent' -Value $MemoryData.'PageFile %' -NoPerfData;
($Critical)
) | Out-Null;
return (New-IcingaCheckresult -Check $MemoryCheck -NoPerfData $TRUE -Compile); # PageFile To-Do
$MemoryPerc.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
$MemoryByte.WarnOutOfRange($WarningPercent).CritOutOfRange($CriticalPercent) | Out-Null;
$MemoryPackage.AddCheck($MemoryPerc);
$MemoryPackage.AddCheck($MemoryByte);
return (New-IcingaCheckResult -Check $MemoryPackage -NoPerfData $TRUE -Compile);
} }

View file

@ -1,27 +1,21 @@
function Get-IcingaMemoryPerformanceCounter() function Get-IcingaMemoryPerformanceCounter()
{ {
$MemoryStart = (Show-IcingaPerformanceCounters -CounterCategory 'Memory'); $MemoryPercent = New-IcingaPerformanceCounterArray -Counter "\Memory\% committed bytes in use","\Memory\committed bytes","\Paging File(_Total)\% usage"
$MemoryCounter = New-IcingaPerformanceCounterArray -Counter $MemoryStart;
[hashtable]$Result = @{}; [hashtable]$Result = @{};
foreach ($item in $MemoryCounter.Keys) { foreach ($item in $MemoryPercent.Keys) {
$counter = $item.trimstart('\Memory\'); $Result.Add($item, $MemoryPercent[$item]);
$Result.Add($counter, $MemoryCounter[$item]);
} }
return $Result; return $Result;
} }
function Get-IcingaPageFilePerformanceCounter() function Get-IcingaMemoryPerformanceCounterFormated()
{ {
$PageFileStart = (Show-IcingaPerformanceCounters -CounterCategory 'Paging File');
$PageFileCounter = New-IcingaPerformanceCounterArray -Counter $PageFileStart;
[hashtable]$Result = @{}; [hashtable]$Result = @{};
$Result.Add('Memory %', (Get-IcingaMemoryPerformanceCounter).'\Memory\% committed bytes in use'.value);
foreach ($item in $PageFileCounter.Keys) { $Result.Add('Memory GigaByte', (ConvertTo-GigaByte ([decimal](Get-IcingaMemoryPerformanceCounter).'\Memory\committed bytes'.value) -Unit Byte));
$counter = $item.trimstart('\Paging File\'); $Result.Add('PageFile %', (Get-IcingaMemoryPerformanceCounter).'\Paging File(_Total)\% usage'.value);
$Result.Add($counter, $PageFileCounter[$item]);
}
return $Result; return $Result;
} }