Update check-swap-space.ps1

This commit is contained in:
Markus Fleschutz 2023-08-06 18:19:20 +02:00
parent 4c3afd9119
commit 1f2dc3a340

View File

@ -7,7 +7,7 @@
Specifies the minimum level (10 GB by default)
.EXAMPLE
PS> ./check-swap-space.ps1
Swap space 10% full, 901MB of 1TB free
Swap space with 1GB at 42%, 748MB free
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -46,14 +46,18 @@ try {
if ($Total -eq 0) {
Write-Output "⚠️ No swap space configured"
} elseif ($Free -eq 0) {
Write-Output "⚠️ Swap space of $(MB2String $Total) is full"
Write-Output "⚠️ Swap space with $(MB2String $Total) is full"
} elseif ($Free -lt $MinLevel) {
Write-Output "⚠️ Swap space of $(MB2String $Total) is nearly full ($(MB2String $Free) free)"
Write-Output "⚠️ Swap space with $(MB2String $Total) is nearly full, only $(MB2String $Free) free"
} elseif ($Used -eq 0) {
Write-Output "✅ Swap space with $(MB2String $Total) reserved"
} else {
[int]$Percent = ($Used * 100) / $Total
Write-Output "✅ Swap space $Percent% full, $(MB2String $Free) of $(MB2String $Total) free"
if ($Percent -ge 90) {
Write-Output "✅ Swap space with $(MB2String $Total) is $Percent% full, $(MB2String $Free) free"
} else {
Write-Output "✅ Swap space with $(MB2String $Total) at $Percent%, $(MB2String $Free) free"
}
}
exit 0 # success
} catch {