#!/bin/sh -Cefu set -Cefu cd /home/1-wire || exit 1 _run() { lockf -t 0 "tmp/${0##*/}.lock" "$0" run > /dev/null 2>&1 } case "${*:-}" in *run*) ;; *) _run ; exit ;; esac export "PATH=$PATH:/usr/local/bin" xpoints=513 ypoints=140 db_in=db/temp_in.rrd db_out=db/temp_out.rrd db_server=db/temp_server.rrd dest=www graph() { local start="$1" local title="$2" local graph="$dest/temp-$start.png" local arg1= local arg2= #if [ "$title" = yearly ] #then # arg1=_ # # arg2='CDEF:temp_in_cf_max=temp_in_cf_max_,1,POP' # # echo $arg1 # echo $arg2 #fi rrdtool graph "$graph.tmp" \ \ --imgformat PNG \ \ --width "$xpoints" \ --height "$ypoints" \ \ --start "-$start" \ \ --title "$title temperatures" \ --vertical-label c \ \ --units-exponent 0 \ --units-length 5 \ \ --slope-mode \ --interlaced \ --alt-y-grid \ \ "DEF:temp_in=$db_in:temp:AVERAGE" \ "DEF:temp_in_cf_min=$db_in:temp:MIN" \ "DEF:temp_in_cf_max$arg1=$db_in:temp:MAX" \ \ "DEF:temp_out=$db_out:temp:AVERAGE" \ "DEF:temp_out_cf_min=$db_out:temp:MIN" \ "DEF:temp_out_cf_max=$db_out:temp:MAX" \ \ "DEF:temp_server=$db_server:temp:AVERAGE" \ "DEF:temp_server_cf_min=$db_server:temp:MIN" \ "DEF:temp_server_cf_max=$db_server:temp:MAX" \ \ $arg2 \ \ 'VDEF:temp_in_min=temp_in_cf_min,MINIMUM' \ 'VDEF:temp_in_max=temp_in_cf_max,MAXIMUM' \ 'VDEF:temp_in_avg=temp_in,AVERAGE' \ 'VDEF:temp_in_last=temp_in,LAST' \ \ 'VDEF:temp_out_min=temp_out_cf_min,MINIMUM' \ 'VDEF:temp_out_max=temp_out_cf_max,MAXIMUM' \ 'VDEF:temp_out_avg=temp_out,AVERAGE' \ 'VDEF:temp_out_last=temp_out,LAST' \ \ 'VDEF:temp_server_min=temp_server_cf_min,MINIMUM' \ 'VDEF:temp_server_max=temp_server_cf_max,MAXIMUM' \ 'VDEF:temp_server_avg=temp_server,AVERAGE' \ 'VDEF:temp_server_last=temp_server,LAST' \ \ 'COMMENT:\s' \ 'COMMENT:\s' \ 'COMMENT:\s' \ 'COMMENT: min max avg last' \ 'COMMENT:\s' \ 'COMMENT:\s' \ 'COMMENT:\s' \ \ 'LINE2:temp_in#DD3F4A:indoor ' \ 'GPRINT:temp_in_min:%6.1lf' \ 'GPRINT:temp_in_max:%6.1lf' \ 'GPRINT:temp_in_avg:%6.1lf' \ 'GPRINT:temp_in_last:%6.1lf\n' \ \ 'LINE2:temp_out#3F4ADD:outdoor ' \ 'GPRINT:temp_out_min:%6.1lf' \ 'GPRINT:temp_out_max:%6.1lf' \ 'GPRINT:temp_out_avg:%6.1lf' \ 'GPRINT:temp_out_last:%6.1lf\n' \ \ 'LINE2:temp_server#4ADD3F:server corner' \ 'GPRINT:temp_server_min:%6.1lf' \ 'GPRINT:temp_server_max:%6.1lf' \ 'GPRINT:temp_server_avg:%6.1lf' \ 'GPRINT:temp_server_last:%6.1lf\n' \ \ 'COMMENT:\s' \ 'COMMENT:\s' \ 'COMMENT:\s' \ "COMMENT: `date '+%Y-%m-%d %H\:%M\:%S %z'`" \ \ > /dev/null 2>&1 if [ -f "$graph.tmp" ] then mv "$graph.tmp" "$graph" fi } graph 1d daily graph 1w weekly graph 1m monthly graph 1y yearly graph 10y decennary sh graph-out.sh