Skip to content

Commit

Permalink
Improve logs: apply structure for monitoring
Browse files Browse the repository at this point in the history
* Add ability to suppress logs
* Refactor variable names
  • Loading branch information
nthx committed Mar 16, 2015
1 parent 06afa42 commit 36fc2dd
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions odroid-xu3-fan-control.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
# Loud fan control script to lower speed of fun based on current
# max temperature of any cpu
#
# works only on XU3 Lite with Ubuntu 14.04.1
# See README.md for details.

#set to false to suppress logs
DEBUG=true

# Make sure only root can run our script
if (( $EUID != 0 )); then
Expand All @@ -17,11 +20,12 @@ TEMPERATURE_FILE="/sys/devices/10060000.tmu/temp"
FAN_MODE_FILE="/sys/devices/odroid_fan.14/fan_mode"
FAN_SPEED_FILE="/sys/devices/odroid_fan.14/pwm_duty"
TEST_EVERY=3 #seconds
speed_fan_to_default=80
new_fan_speed_default=80
LOGGER_NAME=odroid-xu3-fan-control

#make sure after quiting script fan goes to auto control
function cleanup {
logger -t $0 "fan-control quiting. Setting fan to auto"
${DEBUG} && logger -t $LOGGER_NAME "event: quit; temp: auto"
echo 1 > ${FAN_MODE_FILE}
}
trap cleanup EXIT
Expand All @@ -36,28 +40,30 @@ do
echo 0 > ${FAN_MODE_FILE} #to be sure we can manage fan

current_max_temp=`cat ${TEMPERATURE_FILE} | cut -d: -f2 | sort -nr | head -1`
logger -t $0 "current_max_temp: ${current_max_temp}"
${DEBUG} && logger -t $LOGGER_NAME "event: read_max; temp: ${current_max_temp}"

new_fan_speed=0
if (( ${current_max_temp} >= 75000 )); then
speed_fan_to=255
new_fan_speed=255
elif (( ${current_max_temp} >= 70000 )); then
speed_fan_to=200
new_fan_speed=200
elif (( ${current_max_temp} >= 68000 )); then
speed_fan_to=130
new_fan_speed=130
elif (( ${current_max_temp} >= 66000 )); then
speed_fan_to=70
new_fan_speed=70
elif (( ${current_max_temp} >= 63000 )); then
speed_fan_to=65
new_fan_speed=65
elif (( ${current_max_temp} >= 60000 )); then
speed_fan_to=60
new_fan_speed=60
elif (( ${current_max_temp} >= 58000 )); then
speed_fan_to=50
new_fan_speed=50
elif (( ${current_max_temp} >= 55000 )); then
speed_fan_to=30
new_fan_speed=30
else
speed_fan_to=2
new_fan_speed=2
fi
echo ${speed_fan_to} > ${FAN_SPEED_FILE}
${DEBUG} && logger -t $LOGGER_NAME "event: adjust; speed: ${new_fan_speed}"
echo ${new_fan_speed} > ${FAN_SPEED_FILE}

sleep ${TEST_EVERY}
done

0 comments on commit 36fc2dd

Please sign in to comment.