It is currently Sat Jan 16, 2021 10:25 pm
All times are UTC + 8 hours

[how to] fan speed override and fine tuning (v2)

[how to] fan speed override and fine tuning (v2)

Postby sksbir » Thu Jun 08, 2017 8:21 am

Hi
[edit 14/6/2017]
- script force_fanspeed.sh : fixed fan speed and limited time execution. script is here in 1st reply
- script smart_fanspeed.sh : using disks temp sensor to smooth discs temperature by actively acting on the fan speed., script is here
- startup script for smart_fanspeed.sh : in order to start script at boot. see here.

In order to launch and install these scripts, you must be connected to your NAS with ssh, and with root user.


Here is a little script I wrote in response of FAN control on AS6204T

- This script is successfully tested on AS5002T and AS3102T. I cannot guarantee that it will works on other models, specially if they are using more that one fan.
- script is intended for people who knows about using ssh terminal on their NAS.

- Copy paste the script on the NAS, on location of your choice, in a file named force_fanspeed.sh, and make it executable ( chmod +x )
- script syntax is
..../force_fanspeed.sh SPEED DURATION
SPEED : from 30 to 255, 75-80 are optimal : less noisy than "medium", but cooling enough, far more than "auto".
DURATION : in minutes.

script is intended to use has less resources has possible on your NAS. the basic command ( fanctrl -set fanpwm ) works only for 10 seconds, some other process is working here and reverts fan speed every 10 seconds to settings stored in ADM.
That's why this script first make a pause of 9 seconds, and then actively scan when fan speed setting is changed to reinstall it's own setting just 1/10 second after.
script needs about 1mn to really override default fan speed. Don't worry if fan speed reverts temporarily to default settings during the first minute.
once script is breaked or ended, fan speed reverts to default setting stored in ADM.

sample invocation : crontab line, increase fan speed nights, during backup ( ADM setting is "auto" ) :
Code: Select all
00 23 * * * /bin/sh /share/Syst_interne/force_fanspeed.sh 75 480



script content :
Code: Select all
#!/bin/sh

mysynerror() {
        echo $0 SPEED DURATION
        echo with SPEED from 30 to 255
        echo duration in minutes
        echo script needs about 1mn to really override fanspeed
        exit 6
}

if [ "$2" = "" ]
then
        mysynerror
fi

DESIREDPOWER="$1"
DURATION="$2"

FANID=0
##DESIREDPOWER=75 # from about 30 to 255

if [ \( "$DESIREDPOWER" -lt 30 \) -o \( "$DESIREDPOWER" -gt 255 \) ]
then
        mysynerror
fi
if [ "$DURATION" -le 0 ]
then
        mysynerror
fi

COUNTDWN=`expr $DURATION \* 6`

while [ $COUNTDWN -gt 0 ]
do
        CURRPOWER=`fanctrl -getfanspeed|awk ' { print $NF } ' `
        if [ $DESIREDPOWER -ne $CURRPOWER ]
        then
                fanctrl -setfanpwm $FANID $DESIREDPOWER
                ## echo $CURRPOWER to $DESIREDPOWER CPT : $CPT
                CPT=0
                COUNTDWN=`expr $COUNTDWN - 1`
                sleep 9
        else
                sleep 0.1
                CPT=`expr $CPT + 1`
        fi
done
Last edited by sksbir on Wed Oct 18, 2017 4:37 pm, edited 9 times in total.
sksbir
 
Posts: 339
Joined: Tue Aug 25, 2015 9:23 pm

Re: [how to] fan speed override and fine tuning

Postby orion » Thu Jun 08, 2017 10:09 am

Bravo! Thanks for sharing. :D
User avatar
orion
 
Posts: 2850
Joined: Wed May 29, 2013 11:09 am

Re: [how to] fan speed override and fine tuning

Postby MikeG.6.5 » Thu Jun 08, 2017 12:57 pm

Would love to see this with an implementation to read the temp settings from both the CPU sensor and from the HDD's sensors. Then the script could be used instead of auto, where the temps are read and the fan changes according to the cooling needed.

Other than that, this is fantastic. New ways to manipulate our NASes and make things better! Thanks!
MikeG.6.5
 
Posts: 911
Joined: Fri May 15, 2015 1:56 am

smart fanspeed override is here !

Postby sksbir » Sat Jun 10, 2017 8:17 am

MikeG.6.5 wrote:Would love to see this with an implementation to read the temp settings from both the CPU sensor and from the HDD's sensors. Then the script could be used instead of auto, where the temps are read and the fan changes according to the cooling needed....
I heard you, but I was not able to find the way to retrieve CPU temp.

Here is a script which is doing what you say, but just with disk(s) temp. It take the hottest disk into account. The fanspeed override loop is the same has force_fanspeed.sh ( in 1st reply ).

I tryed it on my 2 NAS with success.

copy-paste the content in a file named "smart_fanspeed.sh" in location of your choice, and make it executable ( chmod +x )
- once started, script will never end.
- script will output log on standard output with "-v" option.

running example:
Code: Select all
# ./smart_fanspeed.sh -v
/dev/sda added to list with recognized temp of 43
/dev/sdb added to list with recognized temp of 38
Retained devices for temperature check : /dev/sda /dev/sdb
20170613_22:21:08 hottest disk changed from 15 to 43,raising fanpower from 31 to 92
20170613_23:06:30 hottest disk changed from 43 to 42,raising fanpower from 92 to 90
20170613_23:09:30 hottest disk changed from 42 to 43,raising fanpower from 90 to 92
20170613_23:21:31 hottest disk changed from 43 to 42,raising fanpower from 92 to 90
20170613_23:24:31 hottest disk changed from 42 to 43,raising fanpower from 90 to 92
20170613_23:30:31 hottest disk changed from 43 to 42,raising fanpower from 92 to 90
20170614_00:06:34 hottest disk changed from 42 to 43,raising fanpower from 90 to 92
20170614_00:18:34 hottest disk changed from 43 to 42,raising fanpower from 92 to 90
20170614_02:15:40 hottest disk changed from 42 to 43,raising fanpower from 90 to 92
20170614_02:18:41 hottest disk changed from 43 to 42,raising fanpower from 92 to 90
20170614_03:27:45 hottest disk changed from 42 to 41,raising fanpower from 90 to 88
20170614_03:30:45 hottest disk changed from 41 to 42,raising fanpower from 88 to 90
20170614_05:15:51 hottest disk changed from 42 to 41,raising fanpower from 90 to 88
20170614_05:18:51 hottest disk changed from 41 to 42,raising fanpower from 88 to 90
20170614_05:27:52 hottest disk changed from 42 to 41,raising fanpower from 90 to 88
20170614_05:30:52 hottest disk changed from 41 to 42,raising fanpower from 88 to 90


Script source code:
Code: Select all
#!/bin/sh

if [ "$1" = "-v" ]
then
        VERBOSE=1
fi

FANID=0
DEF_DESIREDPOWER=75 # from about 30 to 255
CYCLETEMPCHECK=18 # every how many 10" cycles we check for temp changes. 6 = every mn
#
# temperature to power grid : GRIDxx=yy : we want power of yy if temp is xx
GRID15=30 ; GRID16=30 ; GRID17=30 ; GRID18=31 ; GRID19=33
GRID20=35 ; GRID21=37 ; GRID22=39 ; GRID23=41 ; GRID24=44
GRID25=47 ; GRID26=50 ; GRID27=54 ; GRID28=59 ; GRID29=65
GRID30=68 ; GRID31=70 ; GRID32=72 ; GRID33=74 ; GRID34=75
GRID35=77 ; GRID36=79 ; GRID37=82 ; GRID38=84 ; GRID39=85
GRID40=86 ; GRID41=88 ; GRID42=90 ; GRID43=92 ; GRID44=94
GRID45=96 ; GRID46=98 ; GRID47=99 ; GRID48=100 ; GRID49=110
GRID50=120 ; GRID51=130 ; GRID52=140 ; GRID53=150 ; GRID54=160
GRID55=170 ; GRID56=180 ; GRID57=190 ; GRID58=210 ; GRID59=230
GRID60=250 ; GRID61=250 ; GRID62=250 ; GRID63=250 ; GRID64=250



#
# let's learn devices which have temperature sensors
#
HOTTESTDISKTEMP=15
LSTDEVICES=""
for DSKDEV in /dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf /dev/sdg
do
        df | grep $DSKDEV | grep USB >/dev/null 2>&1
        if [ $? -ne 0 ]
                then
                TSTTEMP=`smartctl --all $DSKDEV|awk '/^194/ { print $10 } '`
                if [ "$TSTTEMP" != "" ]
                then
                        if [ \( "$TSTTEMP" -gt 15 \) -a \( "$TSTTEMP" -lt 70 \) ]
                        then
                                [ $VERBOSE ] && echo $DSKDEV added to list with recognized temp of $TSTTEMP
                                LSTDEVICES="$LSTDEVICES $DSKDEV"
                        fi
                fi
        fi
done
[ $VERBOSE ] && echo Retained devices for temperature check : $LSTDEVICES

# DESIREDPOWER=$DEF_DESIREDPOWER # from about 30 to 255
DESIREDPOWER=`fanctrl -getfanspeed|awk ' { print $NF } '`
COUNTDWN=0
CPT=0
DELAY=1 # initial loop = no delay

while :
do
#
# temperature check
#
        if [ $COUNTDWN -le 0 ]
        then
                COUNTDWN=$CYCLETEMPCHECK
                # we almost cancel pause because this loop consumes time.
                DELAY=1
                NEW_HOTTESTDISKTEMP=15
                for DSKDEV in $LSTDEVICES
                do
                        TSTTEMP=`smartctl --all $DSKDEV|awk '/^194/ { print $10 } '`
                        if [ "$TSTTEMP" -gt $NEW_HOTTESTDISKTEMP ]
                        then
                                NEW_HOTTESTDISKTEMP=$TSTTEMP
                        fi
                done
                NEW_DESIREDPOWER=`eval echo \\\$GRID$NEW_HOTTESTDISKTEMP`
                if [ "$NEW_DESIREDPOWER" = "" ]
                then
                        NEW_DESIREDPOWER=$DEF_DESIREDPOWER
                fi
                if [ $HOTTESTDISKTEMP != $NEW_HOTTESTDISKTEMP ]
                then
                        if [ $DESIREDPOWER != $NEW_DESIREDPOWER ]
                        then
                                [ $VERBOSE ] && echo `date +%Y%m%d_%T` hottest disk changed from $HOTTESTDISKTEMP to $NEW_HOTTESTDISKTEMP,raising fanpower from $DESIREDPOWER to $NEW_DESIREDPOWER
                                DESIREDPOWER=$NEW_DESIREDPOWER
                        else
                                [ $VERBOSE ] && echo `date +%Y%m%d_%T` hottest disk changed from $HOTTESTDISKTEMP to $NEW_HOTTESTDISKTEMP,fanpower leaved unchanged at $DESIREDPOWER
                        fi
                        HOTTESTDISKTEMP=$NEW_HOTTESTDISKTEMP
                ## else
                        ## [ $VERBOSE ] && echo `date +%Y%m%d_%T` hottest disk leaved unchanged at $HOTTESTDISKTEMP ,fanpower leaved unchanged at $DESIREDPOWER
                fi
        fi

#
# fan override loop
#
        CURRPOWER=`fanctrl -getfanspeed|awk ' { print $NF } ' `
        if [ $DESIREDPOWER -ne $CURRPOWER ]
        then
                fanctrl -setfanpwm $FANID $DESIREDPOWER
                ## echo $CURRPOWER to $DESIREDPOWER CPT : $CPT
                CPT=0
                COUNTDWN=`expr $COUNTDWN - 1`
                sleep $DELAY
                DELAY=9
        else
                sleep 0.1
                CPT=`expr $CPT + 1`
        fi
done
Last edited by sksbir on Thu Jun 15, 2017 2:22 am, edited 3 times in total.
sksbir
 
Posts: 339
Joined: Tue Aug 25, 2015 9:23 pm

Re: [how to] fan speed override and fine tuning (v2)

Postby MikeG.6.5 » Sat Jun 10, 2017 1:31 pm

Went to test this and got a slew of errors. Line 6, then a bunch of line 42's and then a whole bunch of 106's...

Too tired to dig into it tonight, though. Will try messing with it tomorrow to see what the problem could be.

Many thanks for working on this, though. Any way to get more controls... :)
MikeG.6.5
 
Posts: 911
Joined: Fri May 15, 2015 1:56 am

Re: [how to] fan speed override and fine tuning (v2)

Postby sksbir » Sat Jun 10, 2017 7:14 pm

MikeG.6.5 wrote:Went to test this and got a slew of errors. Line 6, then a bunch of line 42's and then a whole bunch of 106's... ....


Hi Mike. I think you were too tired , and made a mistake. The script is running perfectly on my two NAS since several days. There is nothing in 6 1st lines of script which can explains your problem.
The best way to create script is to copy-paste from here directly to vi in ssh session on your NAS.

- I have changed the code of smart_fanspeed.sh : adding a test in order to exclude USB disks ( those who are mounted on /share/USBx )
- I disabled the verbose output when nothing changed, so the output remains short and interesting, even over several days.
- I added a startup script so the script is started when NAS is rebooting:
File /volume1/.@plugins/etc/init.d/S50_smartfanspeed :
Code: Select all
#!/bin/sh
LOGFILE=<YOUR_PATH_HERE>/fanspeed.log

case "$1" in
    start)
fuser $LOGFILE
if [ $? -eq 1 ]
then
        <YOUR PATH_HERE>/smart_fanspeed.sh -v > $LOGFILE 2>&1 &
fi
        ;;

esac


My advice is to set fanspeed in ADM to "medium" or "high". Just in case script is killed, you will not overheat your disks.
sksbir
 
Posts: 339
Joined: Tue Aug 25, 2015 9:23 pm

Re: [how to] fan speed override and fine tuning (v2)

Postby raidsm » Fri Jun 23, 2017 12:23 am

Hi!

great to see this script but I wonder if there's a way to modify the source code instead of overide it with a script? (I know yours is for a certains amount of time)

I know that on synology nases there's a modification possible on the DSM fan control script and you just can change some values depending on temps.

Is there a way to do this on ADM? As I have a SSD I would like to slow down fan speed a bit in auto mode.

I did a search and did'nt find anything useful.
raidsm
 
Posts: 4
Joined: Sun Dec 04, 2016 8:57 am

Re: [how to] fan speed override and fine tuning (v2)

Postby sksbir » Mon Jun 26, 2017 5:25 pm

raidsm wrote:Hi!
great to see this script but I wonder if there's a way to modify the source code instead of overide it with a script? (I know yours is for a certains amount of time)
I know that on synology nases there's a modification possible on the DSM fan control script and you just can change some values depending on temps.
Is there a way to do this on ADM? As I have a SSD I would like to slow down fan speed a bit in auto mode.
I did a search and did'nt find anything useful.

Hi
I never found anything about changing source. That's why I wrote this 2 scripts. take a look at second script ( smart_fanspeed.sh ) , link is in first reply : this script works endless.
sksbir
 
Posts: 339
Joined: Tue Aug 25, 2015 9:23 pm

Re: [how to] fan speed override and fine tuning (v2)

Postby MikeG.6.5 » Wed Aug 23, 2017 10:10 am

I honestly haven't had any time to dig into this.

Lately I seem to spend most of my time deleting spam posts and banning the offending accounts, that I seldom have time to look at any of the posts on the forums. And when I do, I find that in many cases it's a rehash of things that have already been covered.

My apologies. I didn't mean to make a negative comment about these scripts and then abandon them. As fan control hasn't been an issue for me, nor temps on my NAS, they haven't been a priority. RL things have taken the top of the pile and the forums are a sad secondary. (Except for the spammers. I seem to spend an inordinate amount of time dealing with those!)
MikeG.6.5
 
Posts: 911
Joined: Fri May 15, 2015 1:56 am

Re: [how to] fan speed override and fine tuning (v2)

Postby dergilb » Wed Aug 23, 2017 11:07 pm

hmmm is it possible to set the fan to 0? in case that hdds are in hibernate and cpu is idle? or is fan off not supportet by hardware?
dergilb
 
Posts: 10
Joined: Sat Aug 19, 2017 8:15 pm

Next

Return to [Official] For AS50xx/51xx Series

  • You cannot post new topics in this forum
    You cannot reply to topics in this forum
    You cannot edit your posts in this forum
    You cannot delete your posts in this forum
    You cannot post attachments in this forum
  • Who is online

    Users browsing this forum: No registered users and 2 guests