Update check-swap-space.ps1

This commit is contained in:
Markus Fleschutz 2023-08-04 12:59:10 +02:00
parent 306dc4ca1f
commit 11dce73766

View File

@ -6,7 +6,7 @@
.PARAMETER MinLevel .PARAMETER MinLevel
Specifies the minimum level (10 GB by default) Specifies the minimum level (10 GB by default)
.EXAMPLE .EXAMPLE
PS> ./check-swap-space PS> ./check-swap-space.ps1
Swap space uses 63GB of 1856GB Swap space uses 63GB of 1856GB
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
@ -44,19 +44,18 @@ try {
} }
} }
if ($Total -eq 0) { if ($Total -eq 0) {
$Reply = "⚠️ No swap space configured!" Write-Output "⚠️ No swap space configured"
} elseif ($Free -eq 0) { } elseif ($Free -eq 0) {
$Reply = "⚠️ Swap space of $(MB2String $Total) is full!" Write-Output "⚠️ Swap space of $(MB2String $Total) is full"
} elseif ($Free -lt $MinLevel) { } elseif ($Free -lt $MinLevel) {
$Reply = "⚠️ Swap space of $(MB2String $Total) is nearly full ($(MB2String $Free) free)!" Write-Output "⚠️ Swap space of $(MB2String $Total) is nearly full ($(MB2String $Free) free)"
} elseif ($Used -eq 0) { } elseif ($Used -eq 0) {
$Reply = "✅ Swap space with $(MB2String $Total) reserved" Write-Output "✅ Swap space with $(MB2String $Total) reserved"
} elseif ($Used -lt $Free) { } elseif ($Used -lt $Free) {
$Reply = "✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)" Write-Output "✅ Swap space uses $(MB2String $Used) of $(MB2String $Total)"
} else { } else {
$Reply = "✅ Swap space has $(MB2String $Free) of $(MB2String $Total) free" Write-Output "✅ Swap space has $(MB2String $Free) of $(MB2String $Total) free"
} }
Write-Host $Reply
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"