summaryrefslogtreecommitdiff
path: root/envmon/draw-graph.py
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2013-06-20 19:25:15 +0200
committerChristian Franke <nobody@nowhere.ws>2013-06-20 19:25:31 +0200
commit9191312aac429e745388029ba57a29f015378541 (patch)
tree43fbbf740d0e2a0a231accb2db8e5f9df3af6c8c /envmon/draw-graph.py
parent0ab0cbbda438fd30f24273f1db99d76746108a75 (diff)
Add envmon code
Diffstat (limited to 'envmon/draw-graph.py')
-rwxr-xr-xenvmon/draw-graph.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/envmon/draw-graph.py b/envmon/draw-graph.py
new file mode 100755
index 0000000..4e9d637
--- /dev/null
+++ b/envmon/draw-graph.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+import colorgen
+import rrdtool
+import time
+import onewire
+import sys
+
+dir_prefix = '/home/nihilus/envmon/'
+
+datasets = sorted([ (sensor, 'onewire-temp-%s.rrd' % sensor) for sensor in onewire.sensors() ], key = lambda x:x[0])
+datasets += [ ('Outside', 'env-outside.rrd') ]
+
+def graph(name, duration):
+ print >>sys.stderr, "Graphing %s" % name
+ end_struct = time.localtime(time.time() - 450)
+ end = time.mktime(end_struct) - end_struct.tm_sec - 60 * (end_struct.tm_min % 5)
+
+ prefix = [
+ name,
+ '-E',
+ '--end', '%d' % end,
+ '--start', 'end-%ds' % duration,
+ '--width', '800',
+ '--height', '300'
+ ]
+
+ body = []
+ cg = colorgen.ColorGen()
+ for dataset_name, dataset_rrd in datasets:
+ body.append('DEF:temperature-%(name)s=%(filename)s:temperature:AVERAGE:start=end-%(duration)d' % {
+ 'name': dataset_name,
+ 'filename': dir_prefix + dataset_rrd,
+ 'duration': duration + 3600
+ })
+ color = cg.get_next()
+ color = (int(color[0] * 255), int(color[1] * 255), int(color[2] * 255))
+ body.append('LINE2:temperature-%(name)s#%(r)02x%(g)02x%(b)02x:%(name)s' % {
+ 'name': dataset_name,
+ 'r': color[0],
+ 'g': color[1],
+ 'b': color[2]
+ })
+ rrdtool.graph(prefix + body)
+ print >>sys.stderr, "Done with %s" % name
+
+graph('env-day.png', 86400)
+graph('env-week.png', 604800)
+graph('env-month.png', 2592000)
+graph('env-year.png', 31557600)