root/lm-sensors/branches/lm-sensors-3.0.0/prog/rrd/sens_update_rrd @ 4372

Revision 4372, 2.3 KB (checked in by khali, 8 years ago)

rrd: Misc updates
* More hwmon class changes
* Look for rrd in /usr/bin by default
* Add missing shell declarations
* Update URI

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
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 <mdsxyz123@yahoo.com>
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., 675 Mass Ave, Cambridge, MA 02139, USA.
27#
28#################################################################
29#
30if [ $# -lt 1 -o $# -gt 2 ]
31then
32        echo "usage: $0 database.rrd [hwmonN]"
33        exit 1
34elif [ $# -eq 2 ]
35then
36        HWMON=$2
37else
38        HWMON=hwmon0
39fi
40#
41RRDPATH=/usr/bin
42RRDB=$1
43
44SENSDIR=/sys/class/hwmon
45SENS=$SENSDIR/$HWMON/device
46
47if [ ! -d $SENS ]
48then
49        echo "No sensors found in: $SENS"
50        echo "(modprobe sensor modules?)"
51        exit 1
52fi
53
54STRING=N
55#
56# Get the value from these sensor files (/sys)
57#
58SENSORS="fan1 fan2 fan3"
59for i in $SENSORS
60do
61        V="`cat $SENS/${i}_input 2> /dev/null`"
62        if [ $? -ne 0 ]
63        then
64                STRING="${STRING}:U"
65        else
66                STRING="${STRING}:${V}"
67        fi
68done
69#
70# Get the value from these sensor files (/sys) and divide by 1000
71#
72SENSORS="temp1 temp2 temp3 in0 in1 in2 in3 in4 in5 in6"
73for i in $SENSORS
74do
75        V="`cat $SENS/${i}_input 2> /dev/null`"
76        if [ $? -ne 0 ]
77        then
78                STRING="${STRING}:U"
79        else
80                V=`echo "3k0 ${V/-/_} 1000/p"|dc`
81                STRING="${STRING}:${V}"
82        fi
83done
84
85#
86# Get the first value from these /proc files
87#
88SENSORS="loadavg"
89for i in $SENSORS
90do
91        V="`cat /proc/$i 2> /dev/null`"
92        if [ $? -ne 0 ]
93        then
94                STRING="${STRING}:U"
95        else
96                V="`echo $V | cut -d ' ' -f 1`"
97                STRING="${STRING}:${V}"
98        fi
99done
100
101$RRDPATH/rrdtool update $RRDB $STRING
Note: See TracBrowser for help on using the browser.