Search

Recent Posts

Tags


« | Main | »

Simple rrdtool Linux System temperatures

By Dale Reagan | August 12, 2011

While relatively straight-forward using rrdtool can be a bit, well, detailed.  A simple way to get started is explored below by combining Linux Cron, rrdtool, standard system tools and lm-sensors.

Steps to install a working RRD (Round Robin Database) using rrdtool

  1. install Linux (your version of choice)
  2. install lm-sensors (or some other method of extracting hardware temperatures using on-board sensors)
  3. install rrdtool via method of choice (download & un-tar, Yum, Rpm, etc.)
  4. examine your sensor output for temperature sensors and select the ones you want to track
  5. create a simple Bash script to:
  1. create your RRD storage file,
  2. update the file and
  3. graph data from the file

Note that you could use ‘sensord’ to auto-update – probably a ‘better’ solution but, it does require more ‘background setup’.  For this post the emphasis remains on overt shell and cron solutions.

After installing lm-sensors you should have the tool ‘sensors’ available from the command line.  The output for the command below will vary based on  your system but you should see similar results.  Note that for this post only the temperature data is of interest  so the rest will be ignored.

sensors -f
it8718-isa-0e80
Adapter: ISA adapter
in0:         +1.22 V  (min =  +2.03 V, max =  +4.08 V)   ALARM
in1:         +1.12 V  (min =  +4.02 V, max =  +4.06 V)   ALARM
in2:         +3.01 V  (min =  +0.00 V, max =  +4.08 V)   
in3:         +3.04 V  (min =  +0.00 V, max =  +4.08 V)   
in4:         +2.61 V  (min =  +3.82 V, max =  +4.08 V)   ALARM
in5:         +3.36 V  (min =  +0.00 V, max =  +3.95 V)   
in6:         +0.11 V  (min =  +3.06 V, max =  +4.05 V)   ALARM
in7:         +2.59 V  (min =  +0.00 V, max =  +2.03 V)   ALARM
Vbat:        +3.36 V
fan1:       2335 RPM  (min =    0 RPM)
fan2:       1500 RPM  (min =    0 RPM)
fan3:       135000 RPM  (min =    0 RPM)
temp1:      +114.8°F  (low  = +30.2°F, high = -27.4°F)  sensor = thermal diode
temp2:      +118.4°F  (low  = +30.2°F, high = +260.6°F)  sensor = thermistor
temp3:      -198.4°F  (low  = -142.6°F, high = +260.6°F)  sensor = disabled
cpu0_vid:   +1.175 V

For this example I will create a simple Bash script and use functions for each type of activity (create, update, graph, etc.) I start with setting some global variables which can be shared with the functions; I also create the storage folder (if needed):

## define the rrd storage location - change to your needs
ST_DIR=/var/DATA/System/
## create the folder if it does not exist
if [[ ! -d ${ST_DIR} ]] ; then mkdir -p ${ST_DIR} ; echo "${ST_DIR} created..." ; ls -ld ${ST_DIR}  ; fi
## name the RRD (round robin database)
ST_DB=${ST_DIR}/sys-temps.rrd

Now I just need some functions:

function create_rrd {
## if the RRDatabse does NOT exist then create it
if [[ ! -e ${ST_DB} ]]
then
        echo "Creating ${ST_DB}" | ${BOXES}
        rrdtool create ${ST_DB} --start N --step 300 \
                DS:temp1:GAUGE:300:U:U \
                DS:temp2:GAUGE:300:U:U \
                RRA:AVERAGE:0.5:1:12 \
                RRA:AVERAGE:0.5:1:288 \
                RRA:AVERAGE:0.5:12:168 \
                RRA:AVERAGE:0.5:12:720 \
                RRA:AVERAGE:0.5:288:365
        ls -l ${ST_DB}
        echo "RRD Created: ${ST_DB}"
fi
}
###

Now, an ‘update’ function:

###
function update_rrd{
## time to update the data - change temp1/temp2 to YOUR system needs
## extract the temperature values
N_TEMPS=$(sensors -f | egrep "temp1|temp2" | awk '{printf " %s\n", $2}' | sed -e 's/.[+,F]//g' | awk '{printf "%s:", $1} END {printf "\n"}')
## remove any trailing ':'
N_TEMPS=${N_TEMPS%:}
## run the rrdtool update command
rrdtool update ${ST_DB} N:${N_TEMPS}
}
###

A ‘dummy’ function to create graphs

###
function create_graphs {
echo "Fill in with your graphing options..."
}
###

And the ‘main’ portion of the script to call the desired function:

## capture the first argument to the script
OPT="$1"
## ok, do some work!
printf "\t########################\n"
case "${OPT}"
in
        "create") create_rrd ;;
        "update") update_rrd ;;
        "graph") create_graphs ;;
        *) printf "\n\tUsage: $0 {create, update, graph}\n\t###############\n" ;;
esac

Save the above functions and ‘main’ sections into a script and add a simple crontab entry:

### log system temp data via RRD
*/3 * * * * /usr/local/bin/Log.sensors update > /dev/null

When saving such simple scripts I suggest:

  1. place ‘functions’ first
  2. followed by any global variables
  3. followed by script branching/argument processing

Below is the entire script as outlined above – of course additional error checking and enhancements would be advised:


#!/bin/bash
#########################################
# Dale Reagan - sample RRDTool create/update script
# modification to your needs is suggested
#########################################
###
function create_rrd {
## if the RRDatabse does NOT exist then create it
if [[ ! -e ${ST_DB} ]]
then
        echo "Creating ${ST_DB}" | ${BOXES}
        rrdtool create ${ST_DB} --start N --step 300 \
                DS:temp1:GAUGE:300:U:U \
                DS:temp2:GAUGE:300:U:U \
                RRA:AVERAGE:0.5:1:12 \
                RRA:AVERAGE:0.5:1:288 \
                RRA:AVERAGE:0.5:12:168 \
                RRA:AVERAGE:0.5:12:720 \
                RRA:AVERAGE:0.5:288:365
        ls -l ${ST_DB}
        echo "RRD Created: ${ST_DB}"
fi
}
###
###
function update_rrd {
## time to update the data - change temp1/temp2 to YOUR system needs
## extract the temperature values
N_TEMPS=$(sensors -f | egrep "temp1|temp2" | awk '{printf " %s\n", $2}' | sed -e 's/.[+,F]//g' | awk '{printf "%s:", $1} END {printf "\n"}')
## remove any trailing ':'
N_TEMPS=${N_TEMPS%:}
## define the rrdtool update command
CMD="rrdtool update ${ST_DB} N:${N_TEMPS}"
${CMD}
}
###
###
function create_graphs {
echo "Dummy function - add your rrdtool graphing options here..."
}
###
#### MAIN ####
## define the rrd storage location - change to your needs
ST_DIR=/var/DATA/System/
## create the folder if it does not exist
if [[ ! -d ${ST_DIR} ]] ; then mkdir -p ${ST_DIR} ; echo "${ST_DIR} created..." ; ls -ld ${ST_DIR} ; stars ; fi
## name the RRD (round robin database)
ST_DB=${ST_DIR}/sys-temps.rrd
## capture the first argument to the script
OPT="$1"
## ok, do some work!
printf "\t########################\n"
case "${OPT}"
in
        "create") create_rrd ;;
        "update") update_rrd ;;
        "graph") create_graphs ;;
        *) printf "\n\tUsage: $0 {create, update, graph}\n\t###############\n" ;;
esac

Topics: Computer Technology, Unix-Linux-Os | Comments Off on Simple rrdtool Linux System temperatures

Comments are closed.


________________________________________________
YOUR GeoIP Data | Ip: 73.21.121.1
Continent: NA | Country Code: US | Country Name: United States
Region: | State/Region Name: | City:
(US only) Area Code: 0 | Postal code/Zip:
Latitude: 38.000000 | Longitude: -97.000000
Note - if using a mobile device your physical location may NOT be accurate...
________________________________________________

Georgia-USA.Com - Web Hosting for Business
____________________________________