[Progress 001] Creating a CPU Temperature Graph Chart.

Creating a CPU Temperature Graph Chart.

What does this program do? It will graph out a chart and output a PNG image. In this case I made this display on my web-server. This requires understanding how to use cron and bash files.

What it looks like.

From 11/13/2014 Improvement Upon the Script, It now reads off local weather stations to display weather temperature condition and graphs them too.

Start from button to top!

11/13/2014

Another requirement to install.

[code language=”bash”]
sudo apt-get install weather-util
[/code]

The Script.
(Line 4) Change the directory “/home/pi/streamer” to where data will be saved. (I put this in the same location as the script.)
(Line 6) “lax” is reference to lax weather station.  http://www.maketecheasier.com/weather-forecasts-raspberry-pi/
(Line 10) Change the directory “/home/pi/streamer” to where data will be saved. (I put this in the same location as the script.)
(Line 47) Change the directory “/var/www/streamer” to output the picture. (I put this into my website directory.) Also ” > /dev/null” suppress/silence output because rrdtool sends out a message that would spam me.

[code language=”bash”]
#!/bin/bash
###################### RETRIEVE LOCAL WEATHER REPORT ########################
# Set Location
cd /home/pi/streamer
# Save Local Weather Report
sudo weather lax > localweather.txt

###################### CPU TEMPERATURE GRAPHER ##############################
# Set Location
cd /home/pi/streamer
# create database if not exists
[ -f cputemp.rrd ] || {
/usr/bin/rrdtool create cputemp.rrd \
–step 300 \
DS:cputemp:GAUGE:1200:U:U \
RRA:AVERAGE:0.5:1:3200 \
RRA:AVERAGE:0.5:6:3200 \
RRA:AVERAGE:0.5:36:3200 \
RRA:AVERAGE:0.5:144:3200 \
RRA:AVERAGE:0.5:1008:3200 \
RRA:AVERAGE:0.5:4320:3200 \
RRA:AVERAGE:0.5:52560:3200 \
RRA:AVERAGE:0.5:525600:3200
}
[ -f weather.rrd ] || {
/usr/bin/rrdtool create weather.rrd \
–step 300 \
DS:weather:GAUGE:1200:U:U \
RRA:AVERAGE:0.5:1:3200 \
RRA:AVERAGE:0.5:6:3200 \
RRA:AVERAGE:0.5:36:3200 \
RRA:AVERAGE:0.5:144:3200 \
RRA:AVERAGE:0.5:1008:3200 \
RRA:AVERAGE:0.5:4320:3200 \
RRA:AVERAGE:0.5:52560:3200 \
RRA:AVERAGE:0.5:525600:3200
}
# read the temperature and convert .59234. into .59.234. (degrees celsius)
TEMPERATURE=`cat /sys/class/thermal/thermal_zone0/temp`
TEMPERATURE=`echo -n ${TEMPERATURE:0:2}; echo -n .; echo -n ${TEMPERATURE:2}`
# Substring the Weather Report to Celcius Number
WeatherTemp=$(sed -n ‘3p’ < localweather.txt | cut -d'(‘ -f2 | cut -d’ ‘ -f1)
#Creates Data / Updates Data
/usr/bin/rrdtool update cputemp.rrd `date +"%s"`:$TEMPERATURE
/usr/bin/rrdtool update weather.rrd `date +"%s"`:$WeatherTemp
#Make Graph
/usr/bin/rrdtool graph /var/www/streamer/cputemp.png –title="CPU Temperature ($
DEF:temp=cputemp.rrd:cputemp:AVERAGE LINE2:temp#00FF00:CPU \
DEF:WeatherTemp=weather.rrd:weather:AVERAGE AREA:WeatherTemp#cccccc:Weather \
‘GPRINT:temp:LAST:CPU Temp\: %2.1lf C’ \
‘GPRINT:WeatherTemp:LAST:Weather Temp\: %2.1lf C’ \
–vertical-label "Celsius" –width 800 > /dev/null</pre>
<pre>[/code]

Source:

11/11/2014

The requirement to install.

[code language=”bash”]
sudo apt-get install rrdtool
[/code]

The Script.
(Line 4) Change the directory “/home/pi/streamer” to where data will be saved. (I put this in the same location as the script.)
(Line 25) Change the directory “/var/www/streamer” to output the picture. (I put this into my website directory.) Also ” > /dev/null” suppress/silence output because rrdtool sends out a message that would spam me.

[code language=”bash”]
#!/bin/bash
###################### CPU TEMPERATURE GRAPHER ##############################
# Set Location
cd /home/pi/streamer
# create database if not exists
[ -f cputemp.rrd ] || {
/usr/bin/rrdtool create cputemp.rrd \
–step 300 \
DS:cputemp:GAUGE:1200:U:U \
RRA:AVERAGE:0.5:1:3200 \
RRA:AVERAGE:0.5:6:3200 \
RRA:AVERAGE:0.5:36:3200 \
RRA:AVERAGE:0.5:144:3200 \
RRA:AVERAGE:0.5:1008:3200 \
RRA:AVERAGE:0.5:4320:3200 \
RRA:AVERAGE:0.5:52560:3200 \
RRA:AVERAGE:0.5:525600:3200
}
# read the temperature and convert .59234. into .59.234. (degrees celsius)
TEMPERATURE=`cat /sys/class/thermal/thermal_zone0/temp`
TEMPERATURE=`echo -n ${TEMPERATURE:0:2}; echo -n .; echo -n ${TEMPERATURE:2}`
#Creates Data
/usr/bin/rrdtool update cputemp.rrd `date +"%s"`:$TEMPERATURE
#Make Graph
/usr/bin/rrdtool graph /var/www/streamer/cputemp.png DEF:temp=cputemp.rrd:cputemp:AVERAGE LINE2:temp#00FF00 –width 800 > /dev/null
[/code]

Source:

Leave a Reply

Your email address will not be published. Required fields are marked *