diff options
author | Cecil Hugh Watson <knoppmyth@gmail.com> | 2010-09-05 06:13:57 (GMT) |
---|---|---|
committer | Cecil Hugh Watson <knoppmyth@gmail.com> | 2010-09-05 06:13:57 (GMT) |
commit | b172f79fadb565ecfbcec9508f9377d8618a4f4c (patch) | |
tree | bf8823b07e3313c3afa000a9b31e4f9a735cb818 /abs/core/linhes-scripts/limit-mythcommflag.sh | |
parent | f9d54ab7c3853208484e304bc6cf40ab0f79d400 (diff) | |
parent | 5e7027c6194237ca1dc5fcbb3648483a970fb500 (diff) | |
download | linhes_pkgbuild-b172f79fadb565ecfbcec9508f9377d8618a4f4c.zip linhes_pkgbuild-b172f79fadb565ecfbcec9508f9377d8618a4f4c.tar.gz linhes_pkgbuild-b172f79fadb565ecfbcec9508f9377d8618a4f4c.tar.bz2 |
Merge branch 'HEAD' of ssh://cesman@knoppmyth.net/mount/repository/LinHES-PKGBUILD
Diffstat (limited to 'abs/core/linhes-scripts/limit-mythcommflag.sh')
-rwxr-xr-x | abs/core/linhes-scripts/limit-mythcommflag.sh | 95 |
1 files changed, 66 insertions, 29 deletions
diff --git a/abs/core/linhes-scripts/limit-mythcommflag.sh b/abs/core/linhes-scripts/limit-mythcommflag.sh index 8ca61c7..5cd81bb 100755 --- a/abs/core/linhes-scripts/limit-mythcommflag.sh +++ b/abs/core/linhes-scripts/limit-mythcommflag.sh @@ -1,6 +1,7 @@ #!/bin/bash -# limit-mythcommflag.sh v0.1 05/17/09 -# Utility to automatically limit mythcommflag if CPU usage is above a certain level. +# limit-mythcommflag.sh v0.2 03/2/10 +# Utility to automatically limit mythcommflag if CPU system load is above a certain level +# and if backend usage is above a certain level # Uses cpulimit from http://cpulimit.sourceforge.net/ # Free for any use. # Installation: @@ -8,47 +9,83 @@ # chmod +x /usr/LH/bin/limit-mythcommflag.sh # Usage: Executed from runit limit-mythcommflag at boot -# Threshold for when mythcommflag will be paused -CPUTHRESHOLD=43 - -# Limit mythcommflag to percentage -LIMITCPU=20 - -# Log file to write (use /dev/null for no log) -#LOG=/var/log/mythtv/limit-mythcommflag.log -LOG=/dev/null - +#-----OPTIONS______ # Number of seconds to wait between checking for mythcommflag process SLEEP=5 +# Backend and Frontend thresholds above which mythcommflag is stopped +BETHRESHOLD=30 +FETHRESHOLD=55 -#sleep $SLEEP +# FUNCTIONS +limit_cpu() +# Arg_1 = LimitedRangeNum; Arg_2 = CPULimitPercent; Arg_3 = Commflag PID +{ +if [ $ALREADYLIMITED -ne $1 ] ; then + if [ $cpulimit_pid -ne 0 ]; then + kill $cpulimit_pid + fi + cpulimit -p $3 -l $2 & + cpulimit_pid=$! + ALREADYLIMITED=$1 +fi +} -touch $LOG +stop_limit() +{ +if [ $ALREADYLIMITED -ne 0 ]; then + if [ $cpulimit_pid -ne 0 ]; then + kill $cpulimit_pid + cpulimit_pid=0 + fi + ALREADYLIMITED=0 +fi +} ALREADYLIMITED=0 +STOPPED=0 +cpulimit_pid=0 while true; do PROCCOMMFLAG=`pidof mythcommflag` - if [ -n "${PROCCOMMFLAG}" ] - then - FRONTENDCPU=`top -bn1u mythtv | grep mythfrontend | awk '{ print $9 }'` - if [ "$FRONTENDCPU" -ge "$CPUTHRESHOLD" ] - then - echo "$(date) FE CPU $FRONTENDCPU% is greater than $CPUTHRESHOLD%, LIMIT Commflagging" # >> $LOG - if [ $ALREADYLIMITED -eq 0 ]; then - cpulimit -e mythcommflag -l $LIMITCPU & - cpulimit_pid=$! - ALREADYLIMITED=1 + if [ -n "${PROCCOMMFLAG}" ]; then + BACKENDCPU=`top -bn1u mythtv | grep -m 1 mythbackend | awk '{ print $9 }'` + FRONTENDCPU=`top -bn1u mythtv | grep -m 1 mythfrontend | awk '{ print $9 }'` + if [ "$FRONTENDCPU" = "" ]; then + FRONTENDCPU=0 + fi + if [ "$BACKENDCPU" -ge "$BETHRESHOLD" ]; then + if [ "$FRONTENDCPU" -ge $FETHRESHOLD ]; then + if [ $STOPPED -eq 0 ]; then + kill -s STOP $PROCCOMMFLAG + STOPPED=1 + fi + else + if [ $STOPPED -eq 1 ]; then + kill -s CONT $PROCCOMMFLAG + STOPPED=0 + fi + stop_limit fi else - echo "$(date) FE CPU $FRONTENDCPU% is less than $CPUTHRESHOLD%, UNLIMIT Commflagging" #>> $LOG - if [ $ALREADYLIMITED -eq 1 ]; then - kill $cpulimit_pid - ALREADYLIMITED=0 + if [ $STOPPED -eq 1 ]; then + kill -s CONT $PROCCOMMFLAG + STOPPED=0 fi + case $FRONTENDCPU in + [0-9]|[0-3][0-9] ) + stop_limit;; + [4-5][0-9] ) + limit_cpu "1" "70" $PROCCOMMFLAG;; + [6-7][0-9] ) + limit_cpu "2" "50" $PROCCOMMFLAG;; + [8-9][0-9] ) + limit_cpu "3" "20" $PROCCOMMFLAG;; + [1][0-9][0-9] ) + limit_cpu "4" "10" $PROCCOMMFLAG;; + esac fi # else -# echo "No COMMFLAG Process Active" >> $LOG +# echo "No COMMFLAG Process Active" fi sleep $SLEEP done |