Skip to content

Instantly share code, notes, and snippets.

@Raboo
Last active July 19, 2020 07:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Raboo/eda65914c4bcb2af2b32 to your computer and use it in GitHub Desktop.
Save Raboo/eda65914c4bcb2af2b32 to your computer and use it in GitHub Desktop.
FreeBSD collectd hdd temperature script
#!/bin/sh
# URL https://gist.github.com/Raboo/eda65914c4bcb2af2b32
# add following to sudo
# Cmnd_Alias SMARTCTL = /usr/local/sbin/smartctl
# daemon ALL=(ALL) NOPASSWD: SMARTCTL
# add following to /usr/local/etc/collectd.conf
# LoadPlugin exec
# <Plugin exec>
# Exec "daemon:daemon" "/usr/local/etc/collectd_temp.sh"
# </Plugin>
#
# after run /usr/local/etc/rc.d/collectd restart
PATH=$PATH:/usr/local/bin:/usr/local/sbin
HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
INTERVAL="${COLLECTD_INTERVAL:-120}"
while true
do
# HDD temperatures
for i in $(sysctl -n kern.disks | awk '{for (i=NF; i!=0 ; i--) if(match($i, '/ada/')) print $i }' ) ; do
# this one didn't work as it didn't generate any RRD files.
#echo PUTVAL $HOSTNAME/temperature/$i-`sudo smartctl -a -n standby /dev/$i | awk '/Temperature_Celsius/{DevTemp=$10;} /Serial Number:/{DevSerNum=$3}; /Device Model:/{DevVendor=$3; DevName=$4} END {printf "%s_%s_%s interval=120 N:%s", DevVendor,DevName,DevSerNum,DevTemp }'`;
# this one works and puts it's RRD files in /var/db/collectd/rrd/localhost/disk-adaXX/temperature.rrd
echo PUTVAL $HOSTNAME/disk-$i/temperature interval=$INTERVAL `sudo smartctl -a -n standby /dev/$i | awk '/Temperature_Celsius/{DevTemp=$10;} /Serial Number:/{DevSerNum=$3}; /Device Model:/{DevVendor=$3; DevName=$4} END {printf "N:%s", DevTemp }'`;
done
sleep $INTERVAL
done
@fireglow
Copy link

Just what I was looking for, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment