HDSentinel1 is a brilliant little freeware capable of showing S.M.A.R.T. data from the disks in various ways. Since these values are important in monitoring and I'm using collecd as monitoring system, I needed a way to integrate the two. I ended up using the Exec plugin of collectd.
The steps:
wget http://www.hdsentinel.com/hdslin/hdsentinel_008_x64.zip
unzip hdsentinel_008_x64.zip
chmod 0755 HDSentinel
mv HDSentinel /usr/bin/hdsentinel
Add the monitor scripts:
vim /etc/collect/scripts/hdsentinel.sh
#!/usr/bin/env bash
HOSTNAME=`uname -n`
INTERVAL="${COLLECTD_INTERVAL:-1}"
disks=`ls /dev/sd[a-z]`
while sleep "${INTERVAL}"; do
hdsentinel=`/usr/bin/sudo /usr/bin/hdsentinel`
for disk in ${disks}; do
data=`echo "${hdsentinel}" | grep -A11 ${disk}`
name=`echo "${data}" | grep "HDD Device" | awk '{print $4}'`
disk=${disk##/dev/}
temp=`echo "${data}" | grep "Temperature" | awk '{print $3}'`
echo "PUTVAL "${HOSTNAME}/hdsentinel-${disk}/temperature" interval=$INTERVAL N:${temp}"
tempmax=`echo "${data}" | grep "Highest Temp" | awk '{print $3}'`
echo "PUTVAL "${HOSTNAME}/hdsentinel-${disk}/temperature-max" interval=$INTERVAL N:${tempmax}"
health=`echo "${data}" | grep "Health" | awk '{print $3}'`
echo "PUTVAL "${HOSTNAME}/hdsentinel-${disk}/percent-health" interval=$INTERVAL N:${health}"
performance=`echo "${data}" | grep "Performance" | awk '{print $3}'`
echo "PUTVAL "${HOSTNAME}/hdsentinel-${disk}/percent-performance" interval=$INTERVAL N:${performance}"
done
done
Note: "percent" and "temperature" are types of collectd. Thx deadite662!
Add the collectd plugin:
vim /etc/collectd/collectd.conf
LoadPlugin exec
<plugin exec>
Exec "nobody" "/etc/collectd/scripts/hdsentinel.sh"
</plugin>
Add "nobody" to sudoers, but only for hdsentinel ( install sudo if you need to, hdsentinel needs root access to run, but collectd will not exec with root user ):
vim /etc/sudoers
# add to the end
nobody ALL=(ALL) NOPASSWD: /usr/bin/hdsentinel
(Oh, by the way: this entry was written by Peter Molnar, and originally posted on petermolnar dot net.)