mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Memory check uses Used Memory again (Auto-Detect: Draft for Unit Size)
This commit is contained in:
parent
ea8b4f9571
commit
c587467c89
2 changed files with 46 additions and 19 deletions
|
|
@ -52,6 +52,10 @@ Import-IcingaLib core\tools;
|
||||||
.NOTES
|
.NOTES
|
||||||
#>
|
#>
|
||||||
|
|
||||||
|
<#
|
||||||
|
if ($bytes > 1099511627776) { return sprintf('%.2f TB', $bytes / 1099511627776); } elseif ($bytes > 1073741824) { return sprintf('%.2f GB', $bytes / 1073741824); } elseif ($bytes > 1048576) { return sprintf('%.2f MB', $bytes / 1048576); } else { return sprintf('%.2f KB', $bytes / 1024);
|
||||||
|
#>
|
||||||
|
|
||||||
function Invoke-IcingaCheckMemory()
|
function Invoke-IcingaCheckMemory()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
|
|
@ -59,32 +63,55 @@ function Invoke-IcingaCheckMemory()
|
||||||
[string]$WarningBytes = $null,
|
[string]$WarningBytes = $null,
|
||||||
$CriticalPercent = $null,
|
$CriticalPercent = $null,
|
||||||
$WarningPercent = $null,
|
$WarningPercent = $null,
|
||||||
[switch]$PageFile,
|
# [switch]$PageFile,
|
||||||
[ValidateSet(0, 1, 2, 3)]
|
[ValidateSet(0, 1, 2, 3)]
|
||||||
[int]$Verbosity = 0,
|
[int]$Verbosity = 0,
|
||||||
[switch]$NoPerfData
|
[switch]$NoPerfData
|
||||||
);
|
);
|
||||||
|
|
||||||
If ([string]::IsNullOrEmpty($CriticalBytes) -eq $FALSE) {
|
If ([string]::IsNullOrEmpty($CriticalBytes) -eq $FALSE) {
|
||||||
[decimal]$CrticalConverted = Convert-Bytes $CriticalBytes -Unit B
|
$CrticalConvertedAll = Convert-Bytes $CriticalBytes -Unit B
|
||||||
|
[decimal]$CriticalConverted = $CriticalConvertedAll.value
|
||||||
|
|
||||||
}
|
}
|
||||||
If ([string]::IsNullOrEmpty($WarningBytes) -eq $FALSE) {
|
If ([string]::IsNullOrEmpty($WarningBytes) -eq $FALSE) {
|
||||||
[decimal]$WarningConverted = Convert-Bytes $WarningBytes -Unit B
|
$WarningConvertedAll = Convert-Bytes $WarningBytes -Unit B
|
||||||
|
[decimal]$WarningConverted = $WarningConvertedAll.value
|
||||||
}
|
}
|
||||||
|
|
||||||
$MemoryPackage = New-IcingaCheckPackage -Name 'Memory Usage' -OperatorAnd -Verbos $Verbosity;
|
$MemoryPackage = New-IcingaCheckPackage -Name 'Memory Usage' -OperatorAnd -Verbos $Verbosity;
|
||||||
$MemoryData = (Get-IcingaMemoryPerformanceCounter);
|
$MemoryData = (Get-IcingaMemoryPerformanceCounter);
|
||||||
|
|
||||||
$MemoryPerc = New-IcingaCheck -Name 'Memory Percent Available' -Value $MemoryData['Memory Available %'] -Unit '%';
|
# Auto-Detect?
|
||||||
|
If (($MemoryData['Memory Total Bytes'] / [math]::Pow(2, 50)) -ge 1) {
|
||||||
|
$Unit = "PB"
|
||||||
|
} elseif (($MemoryData['Memory Total Bytes'] / [math]::Pow(2, 40)) -ge 1) {
|
||||||
|
$Unit = "TB"
|
||||||
|
} elseif (($MemoryData['Memory Total Bytes'] / [math]::Pow(2, 30)) -ge 1) {
|
||||||
|
$Unit = "GB"
|
||||||
|
} elseif (($MemoryData['Memory Total Bytes'] / [math]::Pow(2, 20)) -ge 1) {
|
||||||
|
$Unit = "MB"
|
||||||
|
} elseif (($MemoryData['Memory Total Bytes'] / [math]::Pow(2, 10)) -ge 1) {
|
||||||
|
$Unit = "KB"
|
||||||
|
} else {
|
||||||
|
$Unit = "B"
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host $Unit
|
||||||
|
|
||||||
|
$MemoryPerc = New-IcingaCheck -Name 'Memory Percent Used' -Value $MemoryData['Memory Used %'] -Unit '%';
|
||||||
$MemoryByteUsed = New-IcingaCheck -Name "Used Bytes" -Value $MemoryData['Memory Used Bytes'] -Unit 'B';
|
$MemoryByteUsed = New-IcingaCheck -Name "Used Bytes" -Value $MemoryData['Memory Used Bytes'] -Unit 'B';
|
||||||
$MemoryByteAvailable = New-IcingaCheck -Name "Available Bytes" -Value $MemoryData['Memory Available Bytes'] -Unit 'B';
|
#$MemoryByteAvailable = New-IcingaCheck -Name "Available Bytes" -Value $MemoryData['Memory Available Bytes'] -Unit 'B';
|
||||||
#$PageFileCheck = New-IcingaCheck -Name 'PageFile Percent' -Value $MemoryData['PageFile %'] -Unit '%';
|
#$PageFileCheck = New-IcingaCheck -Name 'PageFile Percent' -Value $MemoryData['PageFile %'] -Unit '%';
|
||||||
|
|
||||||
|
|
||||||
|
#Kommastellen bedenken!
|
||||||
# PageFile To-Do
|
# PageFile To-Do
|
||||||
$MemoryByteAvailable.WarnIfLowerThan($WarningConverted).CritIfLowerThan($CrticalConverted) | Out-Null;
|
$MemoryByteUsed.WarnOutOfRange($WarningConverted).CritOutOfRange($CrticalConverted) | Out-Null;
|
||||||
$MemoryPerc.WarnIfLowerThan($WarningPercent).CritIfLowerThan($CriticalPercent) | Out-Null;
|
$MemoryPerc.WarnOutOfRange($WarningPercent).CritOutOfRange($CriticalPercent) | Out-Null;
|
||||||
|
|
||||||
$MemoryPackage.AddCheck($MemoryPerc);
|
$MemoryPackage.AddCheck($MemoryPerc);
|
||||||
$MemoryPackage.AddCheck($MemoryByteAvailable);
|
#$MemoryPackage.AddCheck($MemoryByteAvailable);
|
||||||
$MemoryPackage.AddCheck($MemoryByteUsed);
|
$MemoryPackage.AddCheck($MemoryByteUsed);
|
||||||
|
|
||||||
#$MemoryPackage.AddCheck($PageFileCheck);
|
#$MemoryPackage.AddCheck($PageFileCheck);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ function Get-IcingaMemoryPerformanceCounter()
|
||||||
$MemoryData.Add('Memory Available Bytes', [decimal]($Initial.'\Memory\Available Bytes'.value));
|
$MemoryData.Add('Memory Available Bytes', [decimal]($Initial.'\Memory\Available Bytes'.value));
|
||||||
$MemoryData.Add('Memory Total Bytes', (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory);
|
$MemoryData.Add('Memory Total Bytes', (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory);
|
||||||
$MemoryData.Add('Memory Used Bytes', $MemoryData.'Memory Total Bytes' - $MemoryData.'Memory Available Bytes');
|
$MemoryData.Add('Memory Used Bytes', $MemoryData.'Memory Total Bytes' - $MemoryData.'Memory Available Bytes');
|
||||||
$MemoryData.Add('Memory Available %', 100 - ($MemoryData.'Memory Available Bytes' / $MemoryData.'Memory Total Bytes' * 100));
|
$MemoryData.Add('Memory Used %', 100 - ($MemoryData.'Memory Available Bytes' / $MemoryData.'Memory Total Bytes' * 100));
|
||||||
$MemoryData.Add('PageFile %', $Initial.'\Paging File(_Total)\% usage'.value);
|
$MemoryData.Add('PageFile %', $Initial.'\Paging File(_Total)\% usage'.value);
|
||||||
|
|
||||||
return $MemoryData;
|
return $MemoryData;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue