Last active
July 19, 2020 07:34
-
-
Save Raboo/eda65914c4bcb2af2b32 to your computer and use it in GitHub Desktop.
FreeBSD collectd hdd temperature script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just what I was looking for, thanks!