summaryrefslogtreecommitdiffstats
path: root/abs/core-testing/linhes-scripts/limit-mythcommflag.sh
diff options
context:
space:
mode:
authorMichael Hanson <hansonorders@verison.net>2010-03-25 00:40:35 (GMT)
committerMichael Hanson <hansonorders@verison.net>2010-03-25 00:40:35 (GMT)
commitbd1571b47ff76a352c67f0b87e77843812b6c99b (patch)
tree91d6cdaf99598f7e60c5b0044eda02dc641d84a7 /abs/core-testing/linhes-scripts/limit-mythcommflag.sh
parent369bb6314419c513693a3b5546f6272bd0a6a20c (diff)
parent53c208f892ad378efebba5974dda374f5575f6bf (diff)
downloadlinhes_pkgbuild-bd1571b47ff76a352c67f0b87e77843812b6c99b.zip
linhes_pkgbuild-bd1571b47ff76a352c67f0b87e77843812b6c99b.tar.gz
linhes_pkgbuild-bd1571b47ff76a352c67f0b87e77843812b6c99b.tar.bz2
Merge branch 'master' of mihanson@knoppmyth.net:LinHES-PKGBUILD
Diffstat (limited to 'abs/core-testing/linhes-scripts/limit-mythcommflag.sh')
-rwxr-xr-xabs/core-testing/linhes-scripts/limit-mythcommflag.sh95
1 files changed, 66 insertions, 29 deletions
diff --git a/abs/core-testing/linhes-scripts/limit-mythcommflag.sh b/abs/core-testing/linhes-scripts/limit-mythcommflag.sh
index 8ca61c7..5cd81bb 100755
--- a/abs/core-testing/linhes-scripts/limit-mythcommflag.sh
+++ b/abs/core-testing/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