Last active
April 18, 2020 23:26
-
-
Save feldim2425/0c94b4e9dc56754a073f3cdfbd7688da to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
COUNT_SWAP=0 # Set this to 1 if you want to count free swapspace as free memory | |
WARN=$(( 2 * 1024 * 1024 )) # 2GB has to be in KB so multiply with 1024 2-times | |
INTERVAL=10 # check every 10 seconds | |
INTERVAL_N=30 # check every 30 seconds after the first notification | |
AVAILABLE_MEM=$((`awk '/MemAvailable/{print $2}' /proc/meminfo`)) # get available memory | |
AVAILABLE_SWAP=$((`awk '/SwapFree/{print $2}' /proc/meminfo`)) # get swap memory | |
INTV_C=$INTERVAL | |
while true; do | |
AVAILABLE=$AVAILABLE_MEM | |
if [ $COUNT_SWAP -gt 0 ]; then | |
AVAILABLE=$(($AVAILABLE + $AVAILABLE_SWAP)) | |
fi | |
if [ $AVAILABLE -lt $WARN ]; then | |
# Send notification | |
notify-send -u critical "Warning! Available RAM $(($AVAILABLE_MEM / 1024)) MB & $(($AVAILABLE_SWAP / 1024)) MB Swap" | |
INTV_C=$INTERVAL_N | |
else | |
INTV_C=$INTERVAL | |
fi | |
sleep $INTV_C | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment