Last active
August 29, 2015 14:00
-
-
Save ruzickap/11045020 to your computer and use it in GitHub Desktop.
OpenWrt - Graph internal Turris thermometers (CPU, Board)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir -p /data/temperature_sensors /www3/temperature_sensors | |
#The graphs can be accessed: http://192.168.1.1/myadmin/temperature_sensors | |
ln -s /www3/temperature_sensors /www3/myadmin/temperature_sensors | |
#Create RRDtool database to store the values every 10 minutes (600 seconds) for 10 years (525600 * 600 seconds) | |
rrdtool create /data/temperature_sensors/temperature_sensors.rrd --step 600 \ | |
DS:temp0:GAUGE:1000:-273:5000 DS:temp1:GAUGE:1000:-273:5000 RRA:AVERAGE:0.5:1:525600 \ | |
RRA:MIN:0.5:1:525600 RRA:MAX:0.5:1:525600 | |
#Add cron entry to put the temperatures into the database | |
cat >> /etc/crontabs/root << \EOF | |
*/10 * * * * test -f /data/temperature_sensors/temperature_sensors.rrd && rrdtool update /data/temperature_sensors/temperature_sensors.rrd $(date +\%s):$(thermometer | tr -s \\n ' ' | awk '{print $2":"$4}') | |
EOF | |
#Create main graph script | |
cat > /data/temperature_sensors/temperature_sensors-graph.sh << \EOF | |
#!/bin/sh | |
NAME=$(echo $0 | sed 's@.*/\([^-]*\)-.*@\1@') | |
RRD_FILE="/data/$NAME/$NAME.rrd" | |
DST_FILE="/www3/$NAME/$1.png" | |
RRD_PARAMETERS=' | |
$DST_FILE --end=$(date +%s) --vertical-label "Temperature .C" --width 1024 --height 600 --lower-limit 0 | |
DEF:temp0=$RRD_FILE:temp0:AVERAGE | |
DEF:temp1=$RRD_FILE:temp1:AVERAGE | |
LINE1:temp0#CF00FF:"10 minutes average Board\\n" | |
LINE2:temp1#FF3C00:"10 minutes average CPU\\n" | |
COMMENT:" \\n" | |
GPRINT:temp0:MIN:"Minimum Board\\: %4.1lf .C " | |
GPRINT:temp1:MIN:"Minimum CPU\\: %4.1lf .C " | |
GPRINT:temp0:MAX:"Maximum Board\\: %4.1lf .C " | |
GPRINT:temp1:MAX:"Maximum CPU\\: %4.1lf .C\\n" | |
GPRINT:temp0:AVERAGE:"Average Board\\: %4.1lf .C " | |
GPRINT:temp1:AVERAGE:"Average CPU\\: %4.1lf .C " | |
GPRINT:temp0:LAST:"Current Board\\: %4.1lf .C " | |
GPRINT:temp1:LAST:"Current CPU\\: %4.1lf .C" | |
> /dev/null | |
' | |
case $1 in | |
daily) | |
eval /usr/bin/rrdtool graph --start="end-2days" --title \'Daily graph [`date +"%F %H:%M"`]\' $RRD_PARAMETERS | |
;; | |
weekly) | |
eval /usr/bin/rrdtool graph --start="end-2week" --title \'Weekly graph [`date +"%F %H:%M"`]\' $RRD_PARAMETERS | |
;; | |
monthly) | |
eval /usr/bin/rrdtool graph --start="end-2month" --title \'Monthly graph [`date +"%F %H:%M"`]\' $RRD_PARAMETERS | |
;; | |
yearly) | |
eval /usr/bin/rrdtool graph --start="end-1year" --title \'Yearly graph [`date +"%F %H:%M"`]\' $RRD_PARAMETERS | |
;; | |
2years) | |
eval /usr/bin/rrdtool graph --start="end-2years" --title \'2 Years graph [`date +"%F %H:%M"`]\' $RRD_PARAMETERS | |
;; | |
5years) | |
eval /usr/bin/rrdtool graph --start="end-5years" --title \'5 Years graph [`date +"%F %H:%M"`]\' $RRD_PARAMETERS | |
;; | |
10years) | |
eval /usr/bin/rrdtool graph --start="end-10years" --title \'10 Years graph [`date +"%F %H:%M"`]\' $RRD_PARAMETERS | |
;; | |
*) | |
echo "Please specify $0 [daily|weekly|monthly|yearly|2years|5years|10years]" | |
;; | |
esac | |
EOF | |
chmod a+x /data/temperature_sensors/temperature_sensors-graph.sh | |
#Add cron entry to generate graphs | |
cat >> /etc/crontabs/root << EOF | |
7 * * * * /data/temperature_sensors/temperature_sensors-graph.sh daily | |
1 1 * * * /data/temperature_sensors/temperature_sensors-graph.sh weekly | |
2 1 * * 0 /data/temperature_sensors/temperature_sensors-graph.sh monthly | |
3 1 1 * * /data/temperature_sensors/temperature_sensors-graph.sh yearly | |
4 1 1 1 * /data/temperature_sensors/temperature_sensors-graph.sh 2years | |
5 1 1 1 * /data/temperature_sensors/temperature_sensors-graph.sh 5years | |
6 1 1 1 * /data/temperature_sensors/temperature_sensors-graph.sh 10years | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment