This page presents code associated with the module/unit named above.
#!/bin/sh
# 2020-04-07
# monitor CPU load and throttle via .htaccess if too high
# hysteresis is managed by not running the script frequently
PATH=/bin:/usr/bin:/usr/local/bin
# implement alternative .htaccess settings at this load or higher
threshold=10
# settings files: target, archive for normal, archive for high load
htaccess=/home/boycottn/public_html/.htaccess
normal="${htaccess}.normal"
highload="${htaccess}.highload"
# verify that the source files exist
test -f ${normal} || test -r ${normal} || exit 1
test -f ${highload} || test -r ${highload} || exit 1
# exit on error
set -e
# scrape the current load average from top
load=$(top -b -n 1 | awk -F '[ ,]+' '{print int($12+.5);exit}')
# deal with it
if [ ${load} -ge ${threshold} ]; then
cp ${highload} ${htaccess}
else
cp ${normal} ${htaccess}
fi
exit 0