-
Notifications
You must be signed in to change notification settings - Fork 1
/
collectd_disktemp.sh
executable file
·33 lines (26 loc) · 1.01 KB
/
collectd_disktemp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
# URL https://gist.github.com/Raboo/eda65914c4bcb2af2b32
# add following to sudo
# Cmnd_Alias SMARTCTL = /usr/local/sbin/smartctl
# operator ALL=(ALL) NOPASSWD: SMARTCTL
# add following to /usr/local/etc/collectd.conf
# LoadPlugin exec
# <Plugin exec>
# Exec "operator:operator" "/usr/local/bin/collectd_temp.sh"
# </Plugin>
#
# after run 'sudo service collectd restart'
PATH=$PATH:/usr/local/bin:/usr/local/sbin
HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
INTERVAL="${COLLECTD_INTERVAL:-600}"
while true
do
# HDD temperatures
for i in $(sysctl -n kern.disks | awk '{for (i=NF; i!=0 ; i--) print $i }' ) ; do
if sudo /usr/local/sbin/smartctl -i /dev/$i | grep 'SMART support is: Enabled' > /dev/null
then
echo PUTVAL $HOSTNAME/disk-$i/temperature interval=$INTERVAL `sudo /usr/local/sbin/smartctl -a /dev/$i | awk '/Temperature_Celsius/{DevTemp=$10;} /Serial Number:/{DevSerNum=$3}; /Device Model:/{DevVendor=$3; DevName=$4} END {printf "N:%s", DevTemp }'`;
fi
done
sleep $INTERVAL
done