Skip to content

Commit

Permalink
Add CPU Load Avg check to startup
Browse files Browse the repository at this point in the history
  • Loading branch information
coincashew committed Dec 3, 2024
1 parent 68794ec commit 8b820a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ethpillar.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# 🙌 Ask questions on Discord:
# * https://discord.gg/dEpAVWgFNB

EP_VERSION="3.1.0"
EP_VERSION="3.1.1"

# VARIABLES
export BASE_DIR="$HOME/git/ethpillar" && cd $BASE_DIR
Expand Down Expand Up @@ -1337,5 +1337,6 @@ setWhiptailColors
installNode
applyPatches
checkDiskSpace
checkCPULoad
setNodeMode
menuMain
17 changes: 16 additions & 1 deletion functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,22 @@ checkDiskSpace(){
fi
else
# Notify completion
echo "Free space check completed. Results:"
ohai ">> Free space check results:"
cat "$ALERT_FILE"
fi
}

# Checks and outputs CPU Load. Notify user if load is high.
checkCPULoad(){
cpus=$(lscpu | grep -e "^CPU(s):" | cut -f2 -d: | awk '{print $1}')
cpu_threshold=$(echo "scale=2;${cpus} * 0.9"| bc -l)
ohai ">> CPU Load Avg check results:"
cat <<EOF
##############################################################
CPU Load Avg Check : <$cpu_threshold Normal, >$cpu_threshold Caution, >$cpus Unhealthy
# of CPUs : $cpus
##############################################################
CPU Load Average : $(uptime | awk -F'load average:' '{ print $2 }' | cut -f1 -d,)
CPU Heath Status : $(uptime | awk -F'load average:' '{ print $2 }' | cut -f1 -d, | awk -v num="$cpu_threshold" -v num2="$cpus" '{if ($1 < num) print "✅ Normal"; else if ($1 > num2) print "❌ Unhealthy"; else print "⚠️ Caution"}')
EOF
}

0 comments on commit 8b820a2

Please sign in to comment.