Mercurial > templog
comparison web/log.py @ 63:43ec670f1b75
UI tweaks
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 26 Jun 2012 21:21:40 +0800 |
parents | 62112fc2af21 |
children | 46c43e13a759 |
comparison
equal
deleted
inserted
replaced
61:62112fc2af21 | 63:43ec670f1b75 |
---|---|
24 | 24 |
25 def create_rrd(sensor_id): | 25 def create_rrd(sensor_id): |
26 # start date of 10 seconds into 1970 is used so that we can | 26 # start date of 10 seconds into 1970 is used so that we can |
27 # update with prior values straight away. | 27 # update with prior values straight away. |
28 if 'voltage' in sensor_id: | 28 if 'voltage' in sensor_id: |
29 args = [ 'DS:temp:GAUGE:7200:-1:10', | 29 args = [ |
30 'RRA:AVERAGE:0.9999:1:1051200'] | 30 '--step', '3600', |
31 'DS:temp:GAUGE:7200:1:10', | |
32 'RRA:AVERAGE:0.5:1:87600'] | |
31 else: | 33 else: |
32 args = [ 'DS:temp:GAUGE:600:-10:100', | 34 args = [ |
35 '--step', '300', | |
36 'DS:temp:GAUGE:600:-10:100', | |
33 'RRA:AVERAGE:0.5:1:1051200'] | 37 'RRA:AVERAGE:0.5:1:1051200'] |
34 | 38 |
35 rrdtool.create(sensor_rrd_path(sensor_id), | 39 rrdtool.create(sensor_rrd_path(sensor_id), |
36 '--start', '10', | 40 '--start', 'now-60d', |
37 '--step', '300', | |
38 *args) | 41 *args) |
39 | 42 |
40 # stolen from viewmtn, stolen from monotone-viz | 43 # stolen from viewmtn, stolen from monotone-viz |
41 def colour_from_string(str): | 44 def colour_from_string(str): |
42 def f(off): | 45 def f(off): |
57 continue | 60 continue |
58 if 'voltage' in sensor: | 61 if 'voltage' in sensor: |
59 have_volts = True | 62 have_volts = True |
60 vname = 'scalevolts' | 63 vname = 'scalevolts' |
61 graph_args = ['DEF:rawvolts=%(rrdfile)s:temp:AVERAGE:step=3600' % locals(), | 64 graph_args = ['DEF:rawvolts=%(rrdfile)s:temp:AVERAGE:step=3600' % locals(), |
62 'CDEF:scalevolts=rawvolts,0.2,/'] + graph_args | 65 'CDEF:scalevolts=rawvolts,2,-,0.1,/'] + graph_args |
63 else: | 66 else: |
64 vname = 'temp%d' % n | 67 vname = 'temp%d' % n |
65 graph_args.append('DEF:%(vname)s=%(rrdfile)s:temp:AVERAGE' % locals()) | 68 graph_args.append('DEF:%(vname)s=%(rrdfile)s:temp:AVERAGE' % locals()) |
66 width = config.LINE_WIDTH | 69 width = config.LINE_WIDTH |
67 legend = config.SENSOR_NAMES.get(sensor, sensor) | 70 legend = config.SENSOR_NAMES.get(sensor, sensor) |
82 '--color', 'MGRID#aaaaaa', | 85 '--color', 'MGRID#aaaaaa', |
83 '--color', 'BACK#ffffff', | 86 '--color', 'BACK#ffffff', |
84 'VRULE:%d#ee0000' % time.time(), | 87 'VRULE:%d#ee0000' % time.time(), |
85 '--imgformat', 'PNG'] \ | 88 '--imgformat', 'PNG'] \ |
86 + graph_args | 89 + graph_args |
87 if config.GRAPH_FONT: | 90 args += ['--font', 'DEFAULT:11:%s' % config.GRAPH_FONT] |
88 args += ['--font', 'DEFAULT:11:%s' % config.GRAPH_FONT] | 91 args += ['--font', 'WATERMARK:6:%s' % config.GRAPH_FONT] |
89 if have_volts: | 92 if have_volts: |
90 args += ['--right-axis', '0.2:0', # matches the scalevolts CDEF above | 93 args += ['--right-axis', '0.1:2', # matches the scalevolts CDEF above |
91 '--right-axis-format', '%.2lf', | 94 '--right-axis-format', '%.2lf', |
92 '--right-axis-label', 'Voltage'] | 95 '--right-axis-label', 'Voltage'] |
93 | 96 |
94 rrdtool.graph(*args) | 97 rrdtool.graph(*args) |
95 return tempf.read() | 98 return tempf.read() |
108 rrdfile = sensor_rrd_path(sensor_id) | 111 rrdfile = sensor_rrd_path(sensor_id) |
109 # XXX what to do here when it fails... | 112 # XXX what to do here when it fails... |
110 for v in values: | 113 for v in values: |
111 try: | 114 try: |
112 rrdtool.update(rrdfile, v) | 115 rrdtool.update(rrdfile, v) |
113 except Exception, e: | 116 except rrdtool.error, e: |
114 print>>sys.stderr, "Bad rrdtool update '%s'" % v | 117 print>>sys.stderr, "Bad rrdtool update '%s'" % v |
115 traceback.print_exc(file=sys.stderr) | 118 traceback.print_exc(file=sys.stderr) |
116 | 119 |
117 # be paranoid | 120 # be paranoid |
118 f = file(rrdfile) | 121 f = file(rrdfile) |