| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# sens_update_rrd - |
| 4 |
# Update a sensors rrd database. |
| 5 |
# Sample usage: |
| 6 |
# sens_update_rrd /var/lib/database.rrd hwmon0 |
| 7 |
# Sample cron entry: |
| 8 |
# */5 * * * * /usr/local/bin/sens_update_rrd /var/lib/sensors-rrd/sensors.rrd hwmon0 |
| 9 |
# |
| 10 |
################################################################# |
| 11 |
# |
| 12 |
# Copyright 2001,2005 Mark D. Studebaker <[email protected]> |
| 13 |
# |
| 14 |
# This program is free software; you can redistribute it and/or modify |
| 15 |
# it under the terms of the GNU General Public License as published by |
| 16 |
# the Free Software Foundation; either version 2 of the License, or |
| 17 |
# (at your option) any later version. |
| 18 |
# |
| 19 |
# This program is distributed in the hope that it will be useful, |
| 20 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
# GNU General Public License for more details. |
| 23 |
# |
| 24 |
# You should have received a copy of the GNU General Public License |
| 25 |
# along with this program; if not, write to the Free Software |
| 26 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 27 |
# MA 02110-1301 USA. |
| 28 |
# |
| 29 |
################################################################# |
| 30 |
# |
| 31 |
if [ $# -lt 1 -o $# -gt 2 ] |
| 32 |
then |
| 33 |
echo "usage: $0 database.rrd [hwmonN]" |
| 34 |
exit 1 |
| 35 |
elif [ $# -eq 2 ] |
| 36 |
then |
| 37 |
HWMON=$2 |
| 38 |
else |
| 39 |
HWMON=hwmon0 |
| 40 |
fi |
| 41 |
# |
| 42 |
RRDPATH=/usr/bin |
| 43 |
RRDB=$1 |
| 44 |
|
| 45 |
SENSDIR=/sys/class/hwmon |
| 46 |
SENS=$SENSDIR/$HWMON/device |
| 47 |
|
| 48 |
if [ ! -d $SENS ] |
| 49 |
then |
| 50 |
echo "No sensors found in: $SENS" |
| 51 |
echo "(modprobe sensor modules?)" |
| 52 |
exit 1 |
| 53 |
fi |
| 54 |
|
| 55 |
STRING=N |
| 56 |
# |
| 57 |
# Get the value from these sensor files (/sys) |
| 58 |
# |
| 59 |
SENSORS="fan1 fan2 fan3" |
| 60 |
for i in $SENSORS |
| 61 |
do |
| 62 |
V="`cat $SENS/${i}_input 2> /dev/null`" |
| 63 |
if [ $? -ne 0 ] |
| 64 |
then |
| 65 |
STRING="${STRING}:U" |
| 66 |
else |
| 67 |
STRING="${STRING}:${V}" |
| 68 |
fi |
| 69 |
done |
| 70 |
# |
| 71 |
# Get the value from these sensor files (/sys) and divide by 1000 |
| 72 |
# |
| 73 |
SENSORS="temp1 temp2 temp3 in0 in1 in2 in3 in4 in5 in6" |
| 74 |
for i in $SENSORS |
| 75 |
do |
| 76 |
V="`cat $SENS/${i}_input 2> /dev/null`" |
| 77 |
if [ $? -ne 0 ] |
| 78 |
then |
| 79 |
STRING="${STRING}:U" |
| 80 |
else |
| 81 |
V=`echo "3k0 ${V/-/_} 1000/p"|dc` |
| 82 |
STRING="${STRING}:${V}" |
| 83 |
fi |
| 84 |
done |
| 85 |
|
| 86 |
# |
| 87 |
# Get the first value from these /proc files |
| 88 |
# |
| 89 |
SENSORS="loadavg" |
| 90 |
for i in $SENSORS |
| 91 |
do |
| 92 |
V="`cat /proc/$i 2> /dev/null`" |
| 93 |
if [ $? -ne 0 ] |
| 94 |
then |
| 95 |
STRING="${STRING}:U" |
| 96 |
else |
| 97 |
V="`echo $V | cut -d ' ' -f 1`" |
| 98 |
STRING="${STRING}:${V}" |
| 99 |
fi |
| 100 |
done |
| 101 |
|
| 102 |
$RRDPATH/rrdtool update $RRDB $STRING |