DSM-G600, DNS-3xx and NSA-220 Hack Forum

Unfortunately no one can be told what fun_plug is - you have to see it for yourself.

You are not logged in.

Announcement

#1 2011-06-16 11:41:58

Gyngy
Member
Registered: 2011-05-27
Posts: 32

Fancontrol and graph drawing scripts for DNS-320

Hello all NAS tweakers,
I wrote fancontrol and graph maker script for DN-320.

fancontrol_dns320.sh - reading system temperature, hdd1 and hdd2 temperatures, starting/stopping fan while some defined limits reached.
tplot.sh - takes temperature logs from above script and periodicaly (each 5 minutes) makes a graph using GNUPLOT

Note that both scripts need further testing and they are not tuned.

Example 1
Example 2

INSTALL :
1. Place both scripts to /ffp/start/ folder
2. Make executable permissions

Code:

 chmod a+x /ffp/start/fancontrol_dns320.sh
 chmod a+x /ffp/start/tpol.sh

Manual execution:

Code:

sh /ffp/start/fancontrol_dns320.sh start
sh /ffp/start/tpol.sh start

Manual stopping:

Code:

sh /ffp/start/fancontrol_dns320.sh stop
sh /ffp/start/tpol.sh stop

Best regards!

Last edited by Gyngy (2011-06-16 11:53:43)

Offline

 

#2 2011-06-16 11:44:19

Gyngy
Member
Registered: 2011-05-27
Posts: 32

Re: Fancontrol and graph drawing scripts for DNS-320

fancontrol_dns320.sh:

Code:

#!/ffp/bin/sh
#
#  description: Script to get fan control working with DNS-320
#  Written by Johny Mnemonic
#  Edited by Gyngy
#

# PROVIDE: fancontrol
# REQUIRE: LOGIN

. /ffp/etc/ffp.subr

name="fancontrol"
start_cmd="fancontrol_start"
stop_cmd="fancontrol_stop"
status_cmd="fancontrol_status"

# how often to read and store temperatures in seconds
PERIOD="5"
# if you have just one HDD set to "0"
SECOND_HDD=1
LOGFILE="/var/log/fan.log"
# writing temperature to this file :
LOGTEMPFILE="/var/log/fan_temp"
LOGTEMPEXT=".log"

# temperatures hysteresis
SysHigh="55"
SysLow="50"
HddHigh="45"
HddLow="40"
Hyst="2"


# do not edit bellow this line
# ----------------------------
SL=$((SysLow-Hyst))
DL=$((HddLow-Hyst))

logcommand()
   { 
   echo "`/ffp/bin/date +"%b %e %H:%M:%S"`:" $1 >> $LOGFILE
   }

logtemperature()
   { 
   if [ "$5" = "$1" ]
   then 
    TEXT=""
   else
    TEXT="$1"
   fi
   case $TEXT in
    stop) POSITION=5;;
    low) POSITION=10;;
    high) POSITION=15;;
    *) POSITION=20;;
   esac
   echo "`/ffp/bin/date +"%Y-%m-%d %H:%M:%S"`:" "\"$TEXT\" $2 $3 $4 $POSITION" >> $LOGTEMPFILE$(/ffp/bin/date +"%y%m%d")$LOGTEMPEXT
   }

disk1_temp()
    {
    smartctl -d marvell --all /dev/sda |grep Temp | head -c 89 | tail -c2
    }

disk2_temp()
    {
    smartctl -d marvell --all /dev/sdb |grep Temp | head -c 89 | tail -c2
    }
    
system_temp()
    {
    FT_testing -T | tail -c 3 | head -c 2
    }

Fancontrol() {
#!/ffp/bin/sh
    
logcommand "  Starting DNS-320 Fancontrol script"
logcommand "  Current temperatures: Sys: `system_temp`°C, HDD1: `disk1_temp`°C, HDD2: `disk2_temp`°C "

FAN=`fanspeed g`

while /ffp/bin/true; do
        /ffp/bin/sleep $PERIOD
    SYS_TEMP=`system_temp`
    D1_TEMP=`disk1_temp`
    if [ $SECOND_HDD -eq "1" ]; then
        D2_TEMP=`disk2_temp`
    else 
        D2_TEMP="0"
    fi
    OLD_FAN=$FAN
        if [ $SYS_TEMP -ge $SysHigh -o $D1_TEMP -ge $HddHigh -o $D2_TEMP -ge $HddHigh ]; then
            logcommand "Fan speed $FAN"
            if [ $FAN != "high" ]; then
                logcommand "Running fan on high, temperature too high: Sys: $SYS_TEMP°C, HDD1: $D1_TEMP°C, HDD2: $D2_TEMP°C"
                fanspeed h
                FAN=high
            fi
        else
            if [ $SYS_TEMP -ge $SysLow -o $D1_TEMP -ge $HddLow -o $D2_TEMP -ge $HddLow ]; then
                logcommand "Fan speed $FAN"
                if [ $FAN != "low" ]; then
                    logcommand "Running fan on low, temperature high: Sys: $SYS_TEMP°C, HDD1: $D1_TEMP°C, HDD2: $D2_TEMP°C"
                    fanspeed l
                    FAN=low
                fi
            else
                if [ $SYS_TEMP -le $SL -a $D1_TEMP -le $DL -a $D2_TEMP -le $DL ]; then
                    logcommand "Fan speed $FAN"
                    if [ $FAN != "stop" ]; then
                        logcommand "Stopping fan, temperature low: Sys: $SYS_TEMP°C, HDD1: $D1_TEMP°C, HDD2: $D2_TEMP°C"
                        fanspeed s
                        FAN=stop
                    fi
                fi
            fi
        fi
    logtemperature $FAN $SYS_TEMP $D1_TEMP $D2_TEMP $OLD_FAN
    done
}
   
fancontrol_start() {
    if [ ! -e /var/run/fancontrol.pid ] ; then
        logcommand "Starting DNS-320 Fancontrol daemon"
        logcommand "Killing fan_control ..."
        killall fan_control >/dev/null 2>/dev/null &
        Fancontrol & 
        echo $! >> /var/run/fancontrol.pid
    else
        logcommand "Fancontrol daemon already running"
    fi
}

fancontrol_stop() {
    logcommand "Stopping DNS-320 Fancontrol daemon"
    kill -9 `cat /var/run/fancontrol.pid`
    rm /var/run/fancontrol.pid > /dev/null 2> /dev/null
}
    
fancontrol_restart() {
    fancontrol_stop
    fancontrol_start
}

fancontrol_status() {
    if [ -e /var/run/fancontrol.pid ]; then
        echo " Fancontrol daemon is running"
    else
        echo " Fancontrol daemon is not running"
    fi
}

run_rc_command "$1"

Last edited by Gyngy (2011-06-16 11:59:50)

Offline

 

#3 2011-06-16 11:46:06

Gyngy
Member
Registered: 2011-05-27
Posts: 32

Re: Fancontrol and graph drawing scripts for DNS-320

tplot.sh

Code:

#!/ffp/bin/sh

#
#  description: Script to plot temperature chart 
#  Written by Gyngy
#  fancontrol_dns320.sh is needed to provide temperature data
#

# PROVIDE: 
# REQUIRE: LOGIN

. /ffp/etc/ffp.subr

name="tplot"
start_cmd="tplot_start"
stop_cmd="tplot_stop"
status_cmd="tplot_status"

# how often to read and store temperatures in seconds
PERIOD=300

LOGFILE="/var/log/tplot.log"
# reading temperature from this file :
DATAFILE="/var/log/fan_temp"
DATAFILE_EXT=".log"

# writing graphs to folder:
PNG_FOLDER="/hd1/Ajaxpf"


# do not edit bellow this line
# ----------------------------
logcommand()
   { 
   echo "`/ffp/bin/date +"%b %e %H:%M:%S"`:" $1 >> $LOGFILE
   echo "`/ffp/bin/date +"%b %e %H:%M:%S"`:" $1
   }

tplot() {
#!/ffp/bin/sh
    
logcommand "  Starting DNS-320 tplot script"

while /ffp/bin/true; do

    CUR_DATAFILE=$DATAFILE$(/ffp/bin/date +"%y%m%d")$DATAFILE_EXT

    if [ -e $CUR_DATAFILE ]; then
            logcommand "Reading from file $CUR_DATAFILE"
        
        GFX_FILE="${PNG_FOLDER}/temperatures_$(/ffp/bin/date +"%y%m%d").png"
        GNU_FILE="/tmp/gnufile"

        echo "set terminal png nocrop large size 1400,900" > $GNU_FILE
        echo "set output '$GFX_FILE'" >> $GNU_FILE
        echo "set timefmt '%Y-%m-%d %H:%M:%S:'" >> $GNU_FILE
        echo "set xdata time" >> $GNU_FILE
        echo "set yrange [0:60]" >> $GNU_FILE
        echo "plot '$CUR_DATAFILE' u 1:4 w st title 'System','' u 1:5 w st title 'Disk R (Seagate)','' u 1:6 w st title 'Disk L (WD)','' u 1:7:3 w labels title 'FAN'" >> $GNU_FILE
      logcommand "Drawing to file $GFX_FILE"
        gnuplot $GNU_FILE
    
    else
        logcommand "File $CUR_DATAFILE does not exist!"
        fi
        /ffp/bin/sleep $PERIOD

    done
}
   
tplot_start() {
    if [ ! -e /var/run/tplot.pid ] ; then
        logcommand "Starting DNS-320 tplot daemon"
        tplot & 
        echo $! >> /var/run/tplot.pid
    else
        logcommand "tplot daemon already running"
    fi
}

tplot_stop() {
    logcommand "Stopping DNS-320 tplot daemon"
    kill -9 `cat /var/run/tplot.pid`
    rm /var/run/tplot.pid > /dev/null 2> /dev/null
}
    
tplot_restart() {
    tplot_stop
    tplot_start
}

tplot_status() {
    if [ -e /var/run/tplot.pid ]; then
        echo " tplot daemon is running"
    else
        echo " tplot daemon is not running"
    fi
}

run_rc_command "$1"

Offline

 

#4 2011-06-21 22:30:12

dundibandi
New member
Registered: 2011-06-21
Posts: 1

Re: Fancontrol and graph drawing scripts for DNS-320

Hi,

fancontrol_dns320.sh script requires fanspeed binary(?), but I could not find it in my DNS320. Nor can I install it with funpkg or ipkg. Could you tell me where  I can find it?

Last edited by dundibandi (2011-06-21 22:32:19)

Offline

 

#5 2011-06-22 22:24:04

Gyngy
Member
Registered: 2011-05-27
Posts: 32

Re: Fancontrol and graph drawing scripts for DNS-320

dundibandi wrote:

Hi,

fancontrol_dns320.sh script requires fanspeed binary(?), but I could not find it in my DNS320. Nor can I install it with funpkg or ipkg. Could you tell me where  I can find it?

I think that fanspeed is standard DNS-320 binary. You could find it in /usr/sbin/ folder.

Cheers,
Tom

Offline

 

#6 2011-08-06 22:27:33

RayDNS320
Member
Registered: 2011-08-06
Posts: 6

Re: Fancontrol and graph drawing scripts for DNS-320

Thank you very much Gyngy!

A small note:
If you want your HDs to turn off after some minutes, you might want to disable/reset logging.

Offline

 

#7 2011-08-07 23:39:07

Gyngy
Member
Registered: 2011-05-27
Posts: 32

Re: Fancontrol and graph drawing scripts for DNS-320

I am trying to run funplug from USB stick where logs are saved.

;-)

Offline

 

#8 2011-08-30 19:01:42

opfer88
New member
Registered: 2011-08-30
Posts: 2

Re: Fancontrol and graph drawing scripts for DNS-320

The script is working.
But the fan is still on the slow step.
Although the temperature is not reached.

Do you have any ideas?

/e oh  im so sorry. it was the HDD -.-

no problems. all is good.

Last edited by opfer88 (2011-08-30 19:20:11)

Offline

 

#9 2011-09-07 05:02:35

datviet
New member
Registered: 2011-09-07
Posts: 1

Re: Fancontrol and graph drawing scripts for DNS-320

Hello, everyone.

Can someone please show me steps by steps to get this to work on DNS 320? I have fun_plug installed.

I got this when I used this command sh /ffp/start/fancontrol_dns320.sh start.
root@DNS-320:/mnt/HD/HD_a2/ffp/start# sh /ffp/start/fancontrol_dns320.sh start
: not foundfancontrol_dns320.sh: line 7:
: not foundfancontrol_dns320.sh: line 10:
/ffp/start/fancontrol_dns320.sh: .: line 11: can't open /ffp/etc/ffp.subr

I am not familiar with linux.
Thanks in advance.

Offline

 

#10 2011-09-07 10:45:22

Gyngy
Member
Registered: 2011-05-27
Posts: 32

Re: Fancontrol and graph drawing scripts for DNS-320

Hi,
try to use some Linux/Unix friendly editor to copy script from page to file.
PSPad for example.

Best regards!
Gyngy

datviet wrote:

Hello, everyone.

Can someone please show me steps by steps to get this to work on DNS 320? I have fun_plug installed.

I got this when I used this command sh /ffp/start/fancontrol_dns320.sh start.
root@DNS-320:/mnt/HD/HD_a2/ffp/start# sh /ffp/start/fancontrol_dns320.sh start
: not foundfancontrol_dns320.sh: line 7:
: not foundfancontrol_dns320.sh: line 10:
/ffp/start/fancontrol_dns320.sh: .: line 11: can't open /ffp/etc/ffp.subr

I am not familiar with linux.
Thanks in advance.

Offline

 

#11 2011-09-08 00:19:12

jk7gr
Member
Registered: 2011-09-08
Posts: 5

Re: Fancontrol and graph drawing scripts for DNS-320

Hi Gyngy,
I have tried your script and is working fine.

The issue is that the hard disk is constantly working and not going to hibernate. This results the temperature to rise from 34 when hibernation is active to 50 C.
Currently I have investigate and have found that is possible if you transfer the script to ram the disks to hibernate but I don't have the knowledge how to do it.

I would appreciate your contribution here that is much appreciated.

Thanks

Offline

 

#12 2011-09-08 22:25:16

Gyngy
Member
Registered: 2011-05-27
Posts: 32

Re: Fancontrol and graph drawing scripts for DNS-320

Hi,
sorry I do not know how to transfer this to RAM disk.

I did something else - using USB stick to run all ffp from USB. There is only problem - permissions are wrong while mounting USB stick with ext2/3/4 partition. I wrote another script to make fingerprint of all files permissions/owners to file and on start I am reading this file and setting all files permissions.

This is only way I know.

Gyngy

jk7gr wrote:

Hi Gyngy,
I have tried your script and is working fine.

The issue is that the hard disk is constantly working and not going to hibernate. This results the temperature to rise from 34 when hibernation is active to 50 C.
Currently I have investigate and have found that is possible if you transfer the script to ram the disks to hibernate but I don't have the knowledge how to do it.

I would appreciate your contribution here that is much appreciated.

Thanks

Offline

 

#13 2011-09-08 22:58:46

jk7gr
Member
Registered: 2011-09-08
Posts: 5

Re: Fancontrol and graph drawing scripts for DNS-320

Hi Gyngy,
I admire your knowledge. I read some articles yesterday on how to move ffp on USB as well and it seems to me rocket science. I hope you and Johny Mnemonic could join forces. I think the whole community would appreciate it.

Respect....
J

Offline

 

#14 2011-09-09 11:33:25

Gyngy
Member
Registered: 2011-05-27
Posts: 32

Re: Fancontrol and graph drawing scripts for DNS-320

Hi!
I would like to write a tutorial how to do it but it is not 100% functional yet.
I am facing issues with USB flash drive filesystem corruption - I do not know where the problem is yet.

Best regards!
Gyngy

jk7gr wrote:

Hi Gyngy,
I admire your knowledge. I read some articles yesterday on how to move ffp on USB as well and it seems to me rocket science. I hope you and Johny Mnemonic could join forces. I think the whole community would appreciate it.

Respect....
J

Offline

 

#15 2012-02-07 19:51:53

z4k
Member
Registered: 2012-02-04
Posts: 5

Re: Fancontrol and graph drawing scripts for DNS-320

hi

where i can retrive gnuplot for fun_plug??
it don't present i standard packages

tnk!

Last edited by z4k (2012-02-07 19:52:13)

Offline

 

#16 2012-02-08 00:43:16

jp1357
Member
Registered: 2012-01-26
Posts: 5

Re: Fancontrol and graph drawing scripts for DNS-320

http://www.shadowandy.net/2011/12/movin … to-usb.htm

But to move this program to ram is also quite easy. Just mount a tmpfs(or ramfs - not really ideal) folder and copy the script to it, and then run it from there.

Offline

 

Board footer

Powered by PunBB
© Copyright 2002–2010 PunBB