thomas@H8QGL:~$ cat gmetric-cpu-temp
#!/bin/bash
# this script read the core(s) temperature using lm sensors then calculate the average
# and send it to the ganglia using gmetric
# assumes that the lines reported by lm sensors are formated like this
# Core 0: +46.0 C (high = +80.0 C, crit = +100.0 C)
SENSORS=/usr/bin/sensors
GMETRIC=/usr/bin/gmetric
#sensors
let count=0
sum=0.0
for temp in $($SENSORS | grep temp | grep -e '+.*C' | cut -f 2 -d '+' | sed 's/°/ /g' | cut -f 1 -d ' '); do
if (($(echo "$temp > 1.0" | bc) ))
then
sum=$(echo $sum+$temp | bc);
# echo $temp, $sum, $count
let count+=1;
fi
done
temp=$(echo "scale=1; $sum/$count" | bc)
#echo $temp
$GMETRIC -t float -n "avg temp" -u "Celcius" -v $temp
Fehlerhaftes Original here: http://computational.engineering.or.id/LM_Sensors#Integrasi_Dengan_Ganglia
In meiner Version wird das Grad-Celsius Zeichen rausgefiltert.
Es werden nur echte Temperaturen verrechnet, keine min und max Werte.
Falsche Temperaturen wie z.b. 0.8C werden ignoriert nud erst ab 1Grad verrechnet.
thomas@H8QGL:~$ cat /etc/cron.d/sensors
* * * * * root /usr/local/bin/gmetric-cpu-temp