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(
$Critical = $null,
$Warning = $null,
$CriticalPercent = $null,
$WarningPercent = $null,
[switch]$PageFile,
[ValidateSet(0, 1, 2, 3)]
[int]$Verbosity = 0
);
if ($PageFile -eq $TRUE) {
$MemoryData = (Get-IcingaPageFilePerformanceCounter).'(*)\% usage'.'\Paging File(_Total)\% usage'.value
} else {
$MemoryData = (Get-IcingaMemoryPerformanceCounter).'% committed bytes in use'.value;
}
$MemoryPackage = New-IcingaCheckPackage -Name 'Memory Usage' -OperatorAnd -Verbos $Verbosity;
$MemoryData = (Get-IcingaMemoryPerformanceCounterFormated);
$MemoryCheck = New-IcingaCheck -Name '% Memory Check' -Value $MemoryData -NoPerfData;
$MemoryCheck.WarnOutOfRange(
($Warning)
).CritOutOfRange(
($Critical)
) | Out-Null;
$MemoryPerc = New-IcingaCheck -Name 'Memory Percent' -Value $MemoryData.'Memory %' -NoPerfData;
$MemoryByte = New-IcingaCheck -Name 'Memory GigaByte' -Value $MemoryData.'Memory GigaByte' -NoPerfData;
$PageFile = New-IcingaCheck -Name 'PageFile Percent' -Value $MemoryData.'PageFile %' -NoPerfData;
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()
{
$MemoryStart = (Show-IcingaPerformanceCounters -CounterCategory 'Memory');
$MemoryCounter = New-IcingaPerformanceCounterArray -Counter $MemoryStart;
$MemoryPercent = New-IcingaPerformanceCounterArray -Counter "\Memory\% committed bytes in use","\Memory\committed bytes","\Paging File(_Total)\% usage"
[hashtable]$Result = @{};
foreach ($item in $MemoryCounter.Keys) {
$counter = $item.trimstart('\Memory\');
$Result.Add($counter, $MemoryCounter[$item]);
foreach ($item in $MemoryPercent.Keys) {
$Result.Add($item, $MemoryPercent[$item]);
}
return $Result;
}
function Get-IcingaPageFilePerformanceCounter()
function Get-IcingaMemoryPerformanceCounterFormated()
{
$PageFileStart = (Show-IcingaPerformanceCounters -CounterCategory 'Paging File');
$PageFileCounter = New-IcingaPerformanceCounterArray -Counter $PageFileStart;
[hashtable]$Result = @{};
foreach ($item in $PageFileCounter.Keys) {
$counter = $item.trimstart('\Paging File\');
$Result.Add($counter, $PageFileCounter[$item]);
}
$Result.Add('Memory %', (Get-IcingaMemoryPerformanceCounter).'\Memory\% committed bytes in use'.value);
$Result.Add('Memory GigaByte', (ConvertTo-GigaByte ([decimal](Get-IcingaMemoryPerformanceCounter).'\Memory\committed bytes'.value) -Unit Byte));
$Result.Add('PageFile %', (Get-IcingaMemoryPerformanceCounter).'\Paging File(_Total)\% usage'.value);
return $Result;
}