Skip to content

Instantly share code, notes, and snippets.

@robinwl
Created May 2, 2015 17:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robinwl/65c58b07d8de5567225d to your computer and use it in GitHub Desktop.
Save robinwl/65c58b07d8de5567225d to your computer and use it in GitHub Desktop.
HDD temperature in Munin with smartmontools
#!/bin/bash
#
# Configuration
# -------------
# [smartctl_hddtemp_*]
# user root
# group root
# env.attribute 194 # Id of SMART attribute, you probably want to use 194. http://en.wikipedia.org/wiki/S.M.A.R.T.#Known_ATA_S.M.A.R.T._attributes
# env.warning 50 # The environment variables "warning" and "critical" sets the temperature from which Munin starts to warn.
# env.critical 55
#
# Requirements
# ------------
# - smartmontools installed
# - symlink containing target device eg. smartctl_hddtemp_ -> smartctl_hddtemp_sda
. $MUNIN_LIBDIR/plugins/plugin.sh
HDD=${0##*smartctl_hddtemp_}
if [ -n "$attribute" ] && [[ $warning =~ ^-?[0-9]+$ ]]; then
ATTRIBUTE_ID="$attribute"
else
ATTRIBUTE_ID="194"
fi
if [ "$1" = 'config' ]; then
echo "graph_args --lower-limit 0 --upper-limit 100 --rigid"
echo "graph_title HDD temperature $HDD"
echo "graph_category disk"
echo "graph_vlabel Degrees Celsius"
echo "temp.label $HDD"
echo "temp.draw AREA"
echo "temp.colour COLOUR20"
if [ -n "$warning" ] && [[ $warning =~ ^-?[0-9]+$ ]]; then
echo "temp.warning $warning"
fi
if [ -n "$critical" ] && [[ $critical =~ ^-?[0-9]+$ ]]; then
echo "temp.critical $critical"
fi
fi
TEMPERATURE=$(smartctl -d auto -A /dev/sdb |sed -n '/^.*START OF READ SMART DATA SECTION/,$p' |sed -n -e "s/^${ATTRIBUTE_ID} //p" |awk '{ print $3 }' |sed 's/^0*//')
echo "temp.value $TEMPERATURE"
exit 0
@msklywenn
Copy link

msklywenn commented May 25, 2022

Thanks for the script. I spotted a few typos:

  • Change sdb at line 48 to $HDD for this script to run with the drive specified through the magic of the filename
  • Also, line 21, it probably should be $attribute and not $warning in the second part of the test

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