Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
lm sensors rrdtool a sample script
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
smf
n00b
n00b


Joined: 03 Jan 2003
Posts: 10
Location: Netherlands

PostPosted: Tue Dec 02, 2003 12:43 pm    Post subject: lm sensors rrdtool a sample script Reply with quote

I made a script to graph the sensors readout from lm sensors over time. use it as you see fit.

-------------------------------------------------------------
#!/bin/bash
# Run me every 5 minutes
# sensors reading and graphing script
# needs the rrdtools from the mrtg site and lmsensors working.
# (c) Stephan Fassotte 2003

rrdhome="/home/httpd/htdocs/mrtg"
graphhome="/home/httpd/htdocs/mrtg"
# -------------------------Gather information ---------------------------------------
graph_date="`date`"
graph_uptime="`uptime| sed -e "s/.*up //"`"
loadavg=$(cat /proc/loadavg|awk '{print $3}')
# memory
mem=$(cat /proc/meminfo|grep "Mem:")
memtotal=$(cat /proc/meminfo|grep "Mem:"|awk '{print $2}')
memused=$(cat /proc/meminfo|grep "Mem:"|awk '{print $3}')
memfree=$(cat /proc/meminfo|grep "Mem:"|awk '{print $4}')
memshared=$(cat /proc/meminfo|grep "Mem:"|awk '{print $5}')
membuff=$(cat /proc/meminfo|grep "Mem:"|awk '{print $6}')
memcached=$(cat /proc/meminfo|grep "Mem:"|awk '{print $7}')
# temperature
cpu=$(cat /proc/sys/dev/sens*/via*/temp1|awk '{print $3}')
board=$(cat /proc/sys/dev/sens*/via*/temp2|awk '{print $3}')
# fan speed
cpufan=$(cat /proc/sys/dev/sens*/via*/fan1|awk '{print $2}')
casefan=$(cat /proc/sys/dev/sens*/via*/fan2|awk '{print $2}')
# voltage
CpuCore=$(cat /proc/sys/dev/sens*/via*/in0|awk '{print $3}')
IO=$(cat /proc/sys/dev/sens*/via*/in2|awk '{print $3}')
v5=$(cat /proc/sys/dev/sens*/via*/in3|awk '{print $3}')
v12=$(cat /proc/sys/dev/sens*/via*/in4|awk '{print $3}')
# -=-=- rrdtool databases -=-=-
# --- the memory database --------------------------------------------
# create de memory database if needed.
if [ ! -e $rrdhome/memory.rrd ] ; then

rrdtool create $rrdhome/memory.rrd \
DS:memtotal:GAUGE:600:0:$memtotal \
DS:memused:GAUGE:600:0:$memtotal \
DS:memfree:GAUGE:600:0:$memtotal \
DS:memshared:GAUGE:600:0:$memtotal \
DS:membuff:GAUGE:600:0:$memtotal \
DS:memcached:GAUGE:600:0:$memtotal \
RRA:AVERAGE:0.5:1:288

fi
# update memory database
if [ -e $rrdhome/memory.rrd ] ; then

rrdtool update $rrdhome/memory.rrd N:$memtotal:$memused:$memfree:$memshared:$membuff:$memcached
# write graph
rrdtool graph $graphhome/memory.png -t "Memory usage" --vertical-label bytes --start -86400 \
DEF:total=$rrdhome/memory.rrd:memtotal:AVERAGE \
DEF:used=$rrdhome/memory.rrd:memused:AVERAGE \
DEF:free=$rrdhome/memory.rrd:memfree:AVERAGE \
DEF:shared=$rrdhome/memory.rrd:memshared:AVERAGE \
DEF:buff=$rrdhome/memory.rrd:membuff:AVERAGE \
DEF:cached=$rrdhome/memory.rrd:memcached:AVERAGE \
LINE3:used#FF0000:"In use" \
LINE3:buff#17CD2D:Buffered \
LINE3:cached#0434FF:Cached

fi

# --- temperature sensors ---------------------------------
# check for tempandfans.rrd and make it if not there.

if [ ! -e $rrdhome/tempandfans.rrd ]; then

rrdtool create $rrdhome/tempandfans.rrd \
DS:cputemp:GAUGE:600:0:60 \
DS:casetemp:GAUGE:600:0:60 \
DS:cpufan:GAUGE:600:0:5000 \
DS:casefan:GAUGE:600:0:5000 \
RRA:AVERAGE:0.5:1:288

fi

# Update the RRD and write the graph
if [ -e $rrdhome/tempandfans.rrd ]; then

rrdtool update $rrdhome/tempandfans.rrd N:$cpu:$board:$cpufan:$casefan
# Create a daily graph (start 24 hours back in time)
rrdtool graph $graphhome/tempandfans.png -s -1d -h 100 -w 400 -t "System temperature & fans RPM"
-v "(<B0>C) & fan RPM" \
DEF:cputemp=$rrdhome/tempandfans.rrd:cputemp:AVERAGE \
DEF:casetemp=$rrdhome/tempandfans.rrd:casetemp:AVERAGE \
DEF:cpufan=$rrdhome/tempandfans.rrd:cpufan:AVERAGE \
DEF:casefan=$rrdhome/tempandfans.rrd:casefan:AVERAGE \
CDEF:cpufan100=cpufan,100,/ \
CDEF:casefan100=casefan,100,/ \
LINE3:cputemp#FF0703:"CPU Temp." \
LINE3:casetemp#28FF14:"MB temp." \
LINE3:cpufan100#0000FF:"CPU fan RPM X 100" \
LINE3:casefan100#FFF309:"Case fan RPM X 100"
fi
# --- Power suply voltages ------------------------------------------------------
# make the powervoltages rrd file if needed.
if [ ! -e $rrdhome/powervoltages.rrd ]; then

rrdtool create $rrdhome/powervoltages.rrd \
DS:Cpucore:GAUGE:600:0:5 \
DS:IO:GAUGE:600:0:12 \
DS:v5:GAUGE:600:0:5 \
DS:v12:GAUGE:600:0:12 \
RRA:AVERAGE:0.5:1:288

fi
# Update the powervoltages.rrd file and graph the data
if [ -e $rrdhome/powervoltages.rrd ]; then

# collect the data.
rrdtool update $rrdhome/powervoltages.rrd N:$Cpucore:$IO:$v5:$v12
# Create a daily graph (start 24 hours back in time)
rrdtool graph $graphhome/powervoltages.png -s -1d -A -h 100 -w 400 -t "Powersupply voltages" -v "
Volts" \
DEF:cpucore=$rrdhome/powervoltages.rrd:Cpucore:AVERAGE \
DEF:IO=$rrdhome/powervoltages.rrd:IO:AVERAGE \
DEF:v5=$rrdhome/powervoltages.rrd:v5:AVERAGE \
DEF:v12=$rrdhome/powervoltages.rrd:v12:AVERAGE \
LINE3:cpucore#FF0703:"CPU" \
LINE3:IO#28FF14:"IO" \
LINE3:v5#0000FF:"5 volt" \
LINE3:v12#22BA8C:"12 volt"

fi
----------------------------------------------------
Have fun
Back to top
View user's profile Send private message
PoLiPiE
n00b
n00b


Joined: 25 May 2003
Posts: 15
Location: www.pckliniek.be

PostPosted: Sat Dec 06, 2003 1:39 pm    Post subject: Reply with quote

nice man ,

just had to point my sensors into the right directory and now it works very nice

tnx

for the people who want to see this work =>
Memory
Temp and Fans
Powervoltages
_________________
www.pckliniek.be
Back to top
View user's profile Send private message
Souperman
Guru
Guru


Joined: 14 Jul 2003
Posts: 449
Location: Cape Town, South Africa

PostPosted: Thu Apr 08, 2004 1:46 pm    Post subject: Reply with quote

For what it's worth, there's no need to use 'cat' all the time.

e.g.:
Code:
memtotal=$(cat /proc/meminfo|grep "Mem:"|awk '{print $2}')

without cat:
Code:
memtotal=$(grep "Mem:" /proc/meminfo|awk '{print $2}')


Saves you a little process creation overhead every time. ;-)
_________________
moo
Back to top
View user's profile Send private message
tnt
Veteran
Veteran


Joined: 27 Feb 2004
Posts: 1176

PostPosted: Sun Jan 23, 2005 11:43 am    Post subject: Reply with quote

Is it better to put everything (all variables) in one big RRD or make separate RRD for temperature, memory, system load, traffic and so on?

I mean, isn't it less CPU demanding to open and update only one RRD file each time?

:roll:
Back to top
View user's profile Send private message
Rooney
Apprentice
Apprentice


Joined: 07 Aug 2003
Posts: 193
Location: Sheffield, UK

PostPosted: Tue Oct 18, 2005 8:41 am    Post subject: Reply with quote

PoLiPiE wrote:
nice man ,

just had to point my sensors into the right directory and now it works very nice

tnx

for the people who want to see this work =>
Memory
Temp and Fans
Powervoltages


HI im unable to find where the sensors are located i get the following error message when i run the script

Code:
cat: /proc/sys/dev/sens*/via*/temp1: No such file or directory
cat: /proc/sys/dev/sens*/via*/temp2: No such file or directory
cat: /proc/sys/dev/sens*/via*/fan1: No such file or directory
cat: /proc/sys/dev/sens*/via*/fan2: No such file or directory
cat: /proc/sys/dev/sens*/via*/in0: No such file or directory
cat: /proc/sys/dev/sens*/via*/in2: No such file or directory
cat: /proc/sys/dev/sens*/via*/in3: No such file or directory
cat: /proc/sys/dev/sens*/via*/in4: No such file or directory
ERROR: failed to parse data source 600:0:
0x0
./cpu_sensor: line 88: -v: command not found
497x179


I do have everything compiled in to the kernel because i get a good output on the sensor command.

Code:
extreme mrtg # sensors
w83627thf-isa-0290
Adapter: ISA adapter
VCore:     +1.60 V  (min =  +0.00 V, max =  +3.84 V)
+12V:     +12.28 V  (min =  +0.49 V, max =  +4.56 V)
+3.3V:     +3.41 V  (min =  +0.06 V, max =  +3.58 V)
+5V:       +5.09 V  (min =  +3.41 V, max =  +0.05 V)
-12V:      +6.06 V  (min = -14.66 V, max = -14.75 V)
V5SB:      +5.05 V  (min =  +0.97 V, max =  +0.05 V)
VBat:      +0.26 V  (min =  +3.66 V, max =  +3.84 V)
fan1:        0 RPM  (min =  162 RPM, div = 128)
CPU Fan:  2836 RPM  (min = 337500 RPM, div = 2)
fan3:        0 RPM  (min = 2109 RPM, div = 128)
M/B Temp:    +36 C  (high =    +0 C, hyst =  -128 C)   sensor = thermistor     
CPU Temp:  +28.5 C  (high =   +80 C, hyst =   +75 C)   sensor = diode
temp3:     -48.0 C  (high =   +80 C, hyst =   +75 C)   sensor = thermistor     
vid:      +0.000 V  (VRM Version 9.0)
alarms:
beep_enable:
          Sound alarm enabled

extreme mrtg #
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum