mirror of
https://github.com/Icinga/icinga-powershell-framework.git
synced 2025-12-21 07:10:15 -05:00
Fix for IcingaMemoryCheck; Improve speed, changed provider
This commit is contained in:
parent
a911ac1847
commit
badab41eef
2 changed files with 53 additions and 27 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
Import-IcingaLib provider\memory;
|
Import-IcingaLib provider\memory;
|
||||||
|
Import-IcingaLib core\tools;
|
||||||
|
|
||||||
<#
|
<#
|
||||||
.SYNOPSIS
|
.SYNOPSIS
|
||||||
|
|
@ -16,20 +17,44 @@ Import-IcingaLib provider\memory;
|
||||||
[WARNING]: % Memory Check 78.74 is greater than 60
|
[WARNING]: % Memory Check 78.74 is greater than 60
|
||||||
1
|
1
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> Invoke-IcingaCheckMemory -Verbosity 3 -Warning 60 -Critical 80 -PageFile
|
PS> Invoke-IcingaCheckMemory -Unit GB -Critical 1850000KB -Warning 2500000KB -CriticalPercent 80 -WarningPercent 30 -Verbosity 3
|
||||||
[OK]: % Memory Check is 10.99
|
[Warning]: Check package "Memory Usage" is [Warning] (Match All)
|
||||||
0
|
\_ [WARNING]: Memory Percent 35.95% is greater than 30%
|
||||||
|
\_ [OK]: PageFile Percent is 16.42%
|
||||||
|
| 'Memory_Percent'=35.95%;30;80;0;100 'Used_Bytes_in_GB'=3.44;2.5;1.85 'PageFile_Percent'=16.42%;;;0;100
|
||||||
|
1
|
||||||
.PARAMETER Warning
|
.PARAMETER Warning
|
||||||
Used to specify a Warning threshold. In this case an integer value.
|
Used to specify a Warning threshold. In this case an string value.
|
||||||
|
|
||||||
|
The string has to be like, "20B", "20KB", "20MB", "20GB", "20TB", "20TB"
|
||||||
.PARAMETER Critical
|
.PARAMETER Critical
|
||||||
Used to specify a Critical threshold. In this case an integer value.
|
Used to specify a Critical threshold. In this case an string value.
|
||||||
|
|
||||||
|
The string has to be like, "20B", "20KB", "20MB", "20GB", "20TB", "20TB"
|
||||||
|
|
||||||
.PARAMETER Pagefile
|
.PARAMETER Pagefile
|
||||||
Switch which determines whether the pagefile should be used instead.
|
Switch which determines whether the pagefile should be used instead.
|
||||||
If not set memory will be checked.
|
If not set memory will be checked.
|
||||||
|
|
||||||
|
.PARAMETER CriticalPercent
|
||||||
|
Used to specify a Critical threshold. In this case an integer value.
|
||||||
|
|
||||||
|
Like 30 for 30%. If memory usage is above 30%, the check will return CRITICAL.
|
||||||
|
|
||||||
|
.PARAMETER CriticalPercent
|
||||||
|
Used to specify a Critical threshold. In this case an integer value.
|
||||||
|
|
||||||
|
Like 30 for 30%. If memory usage is above 30%, the check will return Warning.
|
||||||
|
|
||||||
|
.PARAMETER Unit
|
||||||
|
Determines output Unit. Allowed Units: 'B', 'KB', 'MB', 'GB', 'TB', 'PB'
|
||||||
|
|
||||||
.INPUTS
|
.INPUTS
|
||||||
System.String
|
System.String
|
||||||
|
|
||||||
.OUTPUTS
|
.OUTPUTS
|
||||||
System.String
|
System.String
|
||||||
|
|
||||||
.LINK
|
.LINK
|
||||||
https://github.com/LordHepipud/icinga-module-windows
|
https://github.com/LordHepipud/icinga-module-windows
|
||||||
.NOTES
|
.NOTES
|
||||||
|
|
@ -38,8 +63,9 @@ Import-IcingaLib provider\memory;
|
||||||
function Invoke-IcingaCheckMemory()
|
function Invoke-IcingaCheckMemory()
|
||||||
{
|
{
|
||||||
param(
|
param(
|
||||||
$Critical = $null,
|
[string]$Critical = $null,
|
||||||
$Warning = $null,
|
[string]$Warning = $null,
|
||||||
|
[string]$Unit = 'B',
|
||||||
$CriticalPercent = $null,
|
$CriticalPercent = $null,
|
||||||
$WarningPercent = $null,
|
$WarningPercent = $null,
|
||||||
[switch]$PageFile,
|
[switch]$PageFile,
|
||||||
|
|
@ -48,21 +74,24 @@ function Invoke-IcingaCheckMemory()
|
||||||
[switch]$NoPerfData
|
[switch]$NoPerfData
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$CrticalConverted = Convert-Bytes $Critical -Unit $Unit
|
||||||
|
$WarningConverted = Convert-Bytes $Warning -Unit $Unit
|
||||||
|
|
||||||
$MemoryPackage = New-IcingaCheckPackage -Name 'Memory Usage' -OperatorAnd -Verbos $Verbosity;
|
$MemoryPackage = New-IcingaCheckPackage -Name 'Memory Usage' -OperatorAnd -Verbos $Verbosity;
|
||||||
$MemoryData = (Get-IcingaMemoryPerformanceCounterFormated);
|
$MemoryData = (Get-IcingaMemoryPerformanceCounter);
|
||||||
|
|
||||||
|
|
||||||
$MemoryPerc = New-IcingaCheck -Name 'Memory Percent' -Value $MemoryData['Memory %'] -Unit '%';
|
$MemoryPerc = New-IcingaCheck -Name 'Memory Percent' -Value $MemoryData['Memory Used %'] -Unit '%';
|
||||||
$MemoryByte = New-IcingaCheck -Name 'Memory GigaByte' -Value $MemoryData['Memory GigaByte'] -Unit 'GB';
|
$MemoryByte = New-IcingaCheck -Name "Used Bytes in $Unit" -Value (Convert-Bytes ([string]::Format('{0}B', $MemoryData['Memory used Bytes'])) -Unit $Unit);
|
||||||
$PageFileCheck = New-IcingaCheck -Name 'PageFile Percent' -Value $MemoryData['PageFile %'] -Unit '%';
|
#$PageFileCheck = New-IcingaCheck -Name 'PageFile Percent' -Value $MemoryData['PageFile %'] -Unit '%';
|
||||||
|
|
||||||
# PageFile To-Do
|
# PageFile To-Do
|
||||||
$MemoryPerc.WarnOutOfRange($Warning).CritOutOfRange($Critical) | Out-Null;
|
$MemoryByte.WarnOutOfRange($WarningConverted).CritOutOfRange($CrticalConverted) | Out-Null;
|
||||||
$MemoryByte.WarnOutOfRange($WarningPercent).CritOutOfRange($CriticalPercent) | Out-Null;
|
$MemoryPerc.WarnOutOfRange($WarningPercent).CritOutOfRange($CriticalPercent) | Out-Null;
|
||||||
|
|
||||||
$MemoryPackage.AddCheck($MemoryPerc);
|
$MemoryPackage.AddCheck($MemoryPerc);
|
||||||
$MemoryPackage.AddCheck($MemoryByte);
|
$MemoryPackage.AddCheck($MemoryByte);
|
||||||
$MemoryPackage.AddCheck($PageFileCheck);
|
#$MemoryPackage.AddCheck($PageFileCheck);
|
||||||
|
|
||||||
return (New-IcingaCheckResult -Check $MemoryPackage -NoPerfData $NoPerfData -Compile);
|
return (New-IcingaCheckResult -Check $MemoryPackage -NoPerfData $NoPerfData -Compile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,18 @@
|
||||||
function Get-IcingaMemoryPerformanceCounter()
|
function Get-IcingaMemoryPerformanceCounter()
|
||||||
{
|
{
|
||||||
$MemoryPercent = New-IcingaPerformanceCounterArray -Counter "\Memory\% committed bytes in use","\Memory\committed bytes","\Paging File(_Total)\% usage"
|
$MemoryPercent = New-IcingaPerformanceCounterArray -Counter "\Memory\% committed bytes in use","\Memory\Available Bytes","\Paging File(_Total)\% usage"
|
||||||
[hashtable]$Result = @{};
|
[hashtable]$Initial = @{};
|
||||||
|
[hashtable]$MemoryData = @{};
|
||||||
|
|
||||||
foreach ($item in $MemoryPercent.Keys) {
|
foreach ($item in $MemoryPercent.Keys) {
|
||||||
$Result.Add($item, $MemoryPercent[$item]);
|
$Initial.Add($item, $MemoryPercent[$item]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $Result;
|
$MemoryData.Add('Memory Available Bytes', [decimal]($Initial.'\Memory\Available Bytes'.value));
|
||||||
}
|
$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 %', $MemoryData.'Memory Available Bytes' / $MemoryData.'Memory Total Bytes' * 100);
|
||||||
|
$MemoryData.Add('PageFile %', $Initial.'\Paging File(_Total)\% usage'.value);
|
||||||
|
|
||||||
function Get-IcingaMemoryPerformanceCounterFormated()
|
return $MemoryData;
|
||||||
{
|
|
||||||
[hashtable]$Result = @{};
|
|
||||||
$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;
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue