root/lm-sensors/trunk/prog/rrd/sens_update_rrd @ 4373

Revision 4373, 3.3 KB (checked in by khali, 6 years ago)

More rrd cleanups:
* Update Makefile and README to mention hwmon class for newer

2.6 kernels

* 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 w83781d-isa-0290
7#       Sample cron entry:
8#               */5 * * * * /usr/local/bin/sens_update_rrd /var/lib/sensors-rrd/sensors.rrd w83781d-isa-0290
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 [ $# -ne 2 ]
31then
32        echo "usage: $0 database.rrd sensor"
33        echo "       sensor example: w83781d-isa-0290 (2.4 kernel)"
34        echo "                       0-0290 (early 2.6 kernel)"
35        echo "                       hwmon0 (kernel 2.6.14 or later)"
36        exit 1
37fi
38#
39RRDPATH=/usr/local/rrdtool/bin
40RRDB=$1
41
42SENSDIR=/proc/sys/dev/sensors
43SDIR=/sys/bus/i2c/devices
44HWMONDIR=/sys/class/hwmon
45SENSDEV=$2
46if [ -d $HWMONDIR ]
47then
48        SYSFS=1
49        SENSDIR=$HWMONDIR
50        SENSDEV=$SENSDEV/device
51elif [ -d $SDIR ]
52then
53        SYSFS=1
54        SENSDIR=$SDIR
55elif [ ! -d $SENSDIR]
56then
57        echo $0: 'No sensors found! (modprobe sensor modules?)'
58        exit 1
59fi
60
61SENS=$SENSDIR/$SENSDEV
62if [ ! -r $SENS ]
63then
64        echo $0: 'No sensors found! (modprobe sensor modules?)'
65        exit 1
66fi
67
68STRING=N
69if [ "$SYSFS" = "1" ]
70then
71        #
72        # Get the value from these sensor files (/sys)
73        #
74        SENSORS="fan1 fan2 fan3"
75        for i in $SENSORS
76        do
77                V="`cat $SENSDIR/$SENSDEV/${i}_input 2> /dev/null`"
78                if [ $? -ne 0 ]
79                then
80                        STRING="${STRING}:U"
81                else
82                        STRING="${STRING}:${V}"
83                fi
84        done
85        #
86        # Get the value from these sensor files (/sys) and divide by 1000
87        #
88        SENSORS="temp1 temp2 temp3 in0 in1 in2 in3 in4 in5 in6"
89        for i in $SENSORS
90        do
91                V="`cat $SENSDIR/$SENSDEV/${i}_input 2> /dev/null`"
92                if [ $? -ne 0 ]
93                then
94                        STRING="${STRING}:U"
95                else
96                        V=`echo "3k0 ${V/-/_} 1000/p"|dc`
97                        STRING="${STRING}:${V}"
98                fi
99        done
100else
101        #
102        # Get the second value from these sensor files (/proc)
103        #
104        SENSORS="fan1 fan2 fan3"
105        for i in $SENSORS
106        do
107                V="`cat $SENSDIR/$SENSDEV/$i 2> /dev/null`"
108                if [ $? -ne 0 ]
109                then
110                        STRING="${STRING}:U"
111                else
112                        V="`echo $V | cut -d ' ' -f 2`"
113                        STRING="${STRING}:${V}"
114                fi
115        done
116        #
117        # Get the third value from these sensor files (/proc)
118        #
119        SENSORS="temp1 temp2 temp3 in0 in1 in2 in3 in4 in5 in6"
120        for i in $SENSORS
121        do
122                V="`cat $SENSDIR/$SENSDEV/$i 2> /dev/null`"
123                if [ $? -ne 0 ]
124                then
125                        STRING="${STRING}:U"
126                else
127                        V="`echo $V | cut -d ' ' -f 3`"
128                        STRING="${STRING}:${V}"
129                fi
130        done
131fi
132
133#
134# Get the first value from these /proc files
135#
136SENSORS="loadavg"
137for i in $SENSORS
138do
139        V="`cat /proc/$i 2> /dev/null`"
140        if [ $? -ne 0 ]
141        then
142                STRING="${STRING}:U"
143        else
144                V="`echo $V | cut -d ' ' -f 1`"
145                STRING="${STRING}:${V}"
146        fi
147done
148
149$RRDPATH/rrdtool update $RRDB $STRING
Note: See TracBrowser for help on using the browser.