memory and swap
This commit is contained in:
parent
a0569441d3
commit
a0d4969463
29
modules/memory.sh
Normal file
29
modules/memory.sh
Normal file
@ -0,0 +1,29 @@
|
||||
#!/bin/sh
|
||||
|
||||
name='Memory'
|
||||
available=1
|
||||
recommend=1
|
||||
|
||||
THRESHOLD=90
|
||||
|
||||
check() {
|
||||
mem_total=$(awk '/^MemTotal:/ {print $2}' /proc/meminfo)
|
||||
mem_avail=$(awk '/^MemAvailable:/ {print $2}' /proc/meminfo)
|
||||
mem_used_pct=$(
|
||||
awk -v t="$mem_total" -v a="$mem_avail" '
|
||||
BEGIN {
|
||||
if (t > 0) {
|
||||
used = t - a;
|
||||
pct = (used * 100) / t;
|
||||
printf "%d", pct;
|
||||
}
|
||||
}
|
||||
'
|
||||
)
|
||||
|
||||
if [ "$mem_used_pct" -ge "$THRESHOLD" ] 2>/dev/null; then
|
||||
warn "memory" "$mem_used_pct" "Memory usage is at ${mem_used_pct}%"
|
||||
else
|
||||
ok "memory" "$mem_used_pct" "Memory usage is at ${mem_used_pct}%"
|
||||
fi
|
||||
}
|
||||
36
modules/swap.sh
Normal file
36
modules/swap.sh
Normal file
@ -0,0 +1,36 @@
|
||||
#!/bin/sh
|
||||
|
||||
name='Swap'
|
||||
available=1
|
||||
recommend=0
|
||||
|
||||
THRESHOLD=90
|
||||
|
||||
|
||||
swap_total=$(awk '/^SwapTotal:/ {print $2}' /proc/meminfo)
|
||||
|
||||
if [ "${swap_total:-0}" -eq 0 ] 2>/dev/null; then
|
||||
available=0
|
||||
fi
|
||||
|
||||
check() {
|
||||
swap_free=$(awk '/^SwapFree:/ {print $2}' /proc/meminfo)
|
||||
|
||||
swap_used_pct=$(
|
||||
awk -v t="$swap_total" -v f="$swap_free" '
|
||||
BEGIN {
|
||||
if (t > 0) {
|
||||
used = t - f;
|
||||
pct = (used * 100) / t;
|
||||
printf "%d", pct;
|
||||
}
|
||||
}
|
||||
'
|
||||
)
|
||||
|
||||
if [ "$swap_used_pct" -ge "$THRESHOLD" ] 2>/dev/null; then
|
||||
warn "swap" "$swap_used_pct" "Swap usage is at ${swap_used_pct}%"
|
||||
else
|
||||
ok "swap" "$swap_used_pct" "Swap usage is at ${swap_used_pct}%"
|
||||
fi
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user