-
Notifications
You must be signed in to change notification settings - Fork 0
/
poolpump_rrd.go
84 lines (75 loc) · 2.48 KB
/
poolpump_rrd.go
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
package main
import (
"fmt"
)
func (r *Rrd) addTemp(name, title string, colorid, which int) {
r.creator.DS(name, "GAUGE", "30", "-273", "1000")
vname := fmt.Sprintf("t%d", which)
cname := fmt.Sprintf("f%d", which)
r.grapher.Def(vname, r.path, name, "AVERAGE")
if name == "solar" {
r.grapher.CDef(cname, vname+",10,/")
} else {
r.grapher.CDef(cname, "9,5,/,"+vname+",*,32,+")
}
r.grapher.Line(2.0, cname, colorStr(colorid), title)
}
func (ppc *PoolPumpController) createRrds() error {
ppc.tempRrd.addTemp("pump", "Pump", 8, 1)
ppc.tempRrd.addTemp("roof", "Roof", 2, 3)
ppc.tempRrd.addTemp("pool", "Pool", 0, 5)
ppc.tempRrd.addTemp("target", "Target", 6, 6)
ppc.tempRrd.AddStandardRRAs()
ppc.tempRrd.Creator().Create(*ppc.config.forceRrd)
tg := ppc.tempRrd.grapher
tg.SetTitle("Temperatures")
tg.SetVLabel("Degrees Farenheit")
tg.SetSize(640, 300) // Config?
tg.SetImageFormat("PNG")
pc := ppc.pumpRrd.Creator()
pc.DS("status", "GAUGE", "30", "-1", "10")
pc.DS("solar", "GAUGE", "30", "-1", "10")
pc.DS("manual", "GAUGE", "30", "-1", "10")
ppc.pumpRrd.AddStandardRRAs()
pc.Create(*ppc.config.forceRrd) // fails if already exists
pg := ppc.pumpRrd.grapher
pg.SetTitle("Pump Activity")
pg.SetVLabel("Status Code")
pg.SetUpperLimit(5.0)
pg.SetRightAxis(1, 0.0)
pg.SetRightAxisLabel("Status Code")
pg.SetSize(640, 200) // Config?
pg.SetImageFormat("PNG")
pg.Def("t1", ppc.pumpRrd.path, "status", "AVERAGE")
pg.Line(2.0, "t1", colorStr(0), "Pump Status")
pg.Def("t2", ppc.pumpRrd.path, "solar", "AVERAGE")
pg.Line(2.0, "t2", colorStr(2), "Solar Status")
pg.Def("t3", ppc.pumpRrd.path, "manual", "AVERAGE")
pg.Line(2.0, "t3", colorStr(6), "Manual Operation")
return nil
}
// UpdateRrd writes updates to RRD files and generates cached graphs
func (ppc *PoolPumpController) UpdateRrd() {
update := fmt.Sprintf("N:%f:%f:%f:%f",
ppc.pumpTemp.Temperature(), ppc.roofTemp.Temperature(),
ppc.runningTemp.Temperature(), ppc.config.cfg.Target)
Debug("Updating TempRrd: %s", update)
err := ppc.tempRrd.Updater().Update(update)
if err != nil {
Error("Could not create PumpRrd: %s", err.Error())
}
solar := 0.01
if ppc.switches.solar.isOn() {
solar = 1.03
}
manual := 0.02
if ppc.switches.ManualState(ppc.config.cfg.RunTime) {
manual = 1.06
}
update = fmt.Sprintf("N:%d.001:%0.3f:%0.3f", ppc.switches.State(), solar, manual)
Debug("Updating PumpRrd: %s", update)
err = ppc.pumpRrd.Updater().Update(update)
if err != nil {
Error("Could not create PumpRrd: %s", err.Error())
}
}