File: sens_update_rrd

package info (click to toggle)
lm-sensors 1%3A2.10.1-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 5,104 kB
  • ctags: 10,474
  • sloc: ansic: 61,469; perl: 7,544; sh: 1,491; makefile: 400; lex: 300; yacc: 291
file content (142 lines) | stat: -rwxr-xr-x 3,214 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#
#    sens_update_rrd -
#	Update a sensors rrd database.
#	Sample usage:
#		sens_update_rrd /var/lib/database.rrd w83781d-isa-0290
#	Sample cron entry:
#		*/5 * * * * /usr/local/bin/sens_update_rrd /var/lib/sensors-rrd/sensors.rrd w83781d-isa-0290
#
#################################################################
#
#    Copyright 2001,2005 Mark D. Studebaker <mdsxyz123@yahoo.com>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#################################################################
#
if [ $# -ne 2 ]
then
	echo "usage: $0 database.rrd sensor"
	echo "       sensor example: w83781d-isa-0290 (2.4) or 0-0290 (2.6)"
	exit 1
fi
#
RRDPATH=/usr/local/rrdtool/bin
RRDB=$1

SENSDIR=/proc/sys/dev/sensors
SDIR=/sys/bus/i2c/devices
if [ ! -d $SENSDIR ]
then
	if [ ! -d $SDIR ]
	then
		echo $0: 'No sensors found! (modprobe sensor modules?)'
		exit 1
	else
		SYSFS=1
		SENSDIR=$SDIR
	fi	
fi

SENSDEV=$2
SENS=$SENSDIR/$SENSDEV
if [ ! -r $SENS ]
then
	echo $0: 'No sensors found! (modprobe sensor modules?)'
	exit 1
fi

STRING=N
if [ "$SYSFS" = "1" ]
then
	#
	# Get the value from these sensor files (/sys)
	#
	SENSORS="fan1 fan2 fan3"
	for i in $SENSORS
	do
		V="`cat $SENSDIR/$SENSDEV/${i}_input 2> /dev/null`"
		if [ $? -ne 0 ]
		then
			STRING="${STRING}:U"
		else
			STRING="${STRING}:${V}"
		fi
	done
	#
	# Get the value from these sensor files (/sys) and divide by 1000
	#
	SENSORS="temp1 temp2 temp3 in0 in1 in2 in3 in4 in5 in6"
	for i in $SENSORS
	do
		V="`cat $SENSDIR/$SENSDEV/${i}_input 2> /dev/null`"
		if [ $? -ne 0 ]
		then
			STRING="${STRING}:U"
		else
			V=`echo "3k0 ${V/-/_} 1000/p"|dc`
			STRING="${STRING}:${V}"
		fi
	done
else
	#
	# Get the second value from these sensor files (/proc)
	#
	SENSORS="fan1 fan2 fan3"
	for i in $SENSORS
	do
		V="`cat $SENSDIR/$SENSDEV/$i 2> /dev/null`"
		if [ $? -ne 0 ]
		then
			STRING="${STRING}:U"
		else
			V="`echo $V | cut -d ' ' -f 2`"
			STRING="${STRING}:${V}"
		fi
	done
	#
	# Get the third value from these sensor files (/proc)
	#
	SENSORS="temp1 temp2 temp3 in0 in1 in2 in3 in4 in5 in6"
	for i in $SENSORS
	do
		V="`cat $SENSDIR/$SENSDEV/$i 2> /dev/null`"
		if [ $? -ne 0 ]
		then
			STRING="${STRING}:U"
		else
			V="`echo $V | cut -d ' ' -f 3`"
			STRING="${STRING}:${V}"
		fi
	done
fi

#
# Get the first value from these /proc files
#
SENSORS="loadavg"
for i in $SENSORS
do
	V="`cat /proc/$i 2> /dev/null`"
	if [ $? -ne 0 ]
	then
		STRING="${STRING}:U"
	else
		V="`echo $V | cut -d ' ' -f 1`"
		STRING="${STRING}:${V}"
	fi
done

$RRDPATH/rrdtool update $RRDB $STRING