-
Notifications
You must be signed in to change notification settings - Fork 0
/
rrdwater_rasp.sh
85 lines (72 loc) · 2.08 KB
/
rrdwater_rasp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
RRDTOOL=/usr/bin/rrdtool
DATABASE=/opt/var/lib/rrd/rrdwater_new.rrd
PERIOD=300
read COLD_NOW < /tmp/cold
read HOT_NOW < /tmp/hot
IMAGE_PATH=/var/www/html/rrd
TITLE_TEXT='water'
UNDER_TEXT='hot'
UNDER_TEXT2='cold'
MIN=0
if ! [ -f $DATABASE ]
then
$RRDTOOL create $DATABASE -s $PERIOD DS:hot:DERIVE:600:U:U \
DS:cold:DERIVE:600:U:U \
RRA:AVERAGE:0.5:1:576 \
RRA:AVERAGE:0.5:6:672 \
RRA:AVERAGE:0.5:24:732 \
RRA:AVERAGE:0.5:144:1460
fi
$RRDTOOL update $DATABASE N:$HOT_NOW:$COLD_NOW
# ============================================================================
DRAW_GRAPHIC()
{
NOW_HOUR=`date +%H`
NOW_MIN=`date +%M`
NOW_SEC=`date +%S`
case $2 in
day)
TIME_TEXT="day"
;;
week)
TIME_TEXT="week"
;;
month)
TIME_TEXT="month"
;;
year)
TIME_TEXT="year"
;;
esac
$RRDTOOL graph $IMAGE_PATH/$1 \
-s -1$2 \
-e now \
-a PNG \
-t "$TITLE_TEXT - $TIME_TEXT" \
-l $MIN \
-r \
-E \
-i \
-R light \
--zoom 1.2 \
-w 550 \
-h 172 \
DEF:hot=$DATABASE:hot:AVERAGE \
LINE1:hot#ff0000:"$UNDER_TEXT" \
GPRINT:hot:MIN:'min\: %2.0lf' \
GPRINT:hot:MAX:'max\: %2.0lf' \
GPRINT:hot:AVERAGE:'average\: %4.1lf' \
GPRINT:hot:LAST:'last\: %2.0lf \n' \
DEF:cold=$DATABASE:cold:AVERAGE \
LINE1:cold#0000ff:"$UNDER_TEXT2" \
GPRINT:cold:MIN:'min\: %2.0lf' \
GPRINT:cold:MAX:'max\: %2.0lf' \
GPRINT:cold:AVERAGE:'average\: %4.1lf' \
GPRINT:cold:LAST:'last\: %2.0lf \n' \
COMMENT:"time \: $NOW_HOUR\:$NOW_MIN\:$NOW_SEC \n"
}
DRAW_GRAPHIC 'dwater_.png' 'day' 1> /dev/null
DRAW_GRAPHIC 'wwater_.png' 'week' 1> /dev/null
DRAW_GRAPHIC 'mwater_.png' 'month' 1> /dev/null
DRAW_GRAPHIC 'ywater_.png' 'year' 1> /dev/null