comparison web/log.py @ 410:910324f14fe4

- few more web tweaks. don't fsync, it's slow.
author Matt Johnston <matt@ucc.asn.au>
date Sun, 26 Aug 2012 20:08:47 +0800
parents 1854abee5a59
children 397ac5c079bf
comparison
equal deleted inserted replaced
409:1854abee5a59 410:910324f14fe4
53 li = f(1) * 0.15 + 0.55 53 li = f(1) * 0.15 + 0.55
54 sat = f(2) * 0.5 + .5 54 sat = f(2) * 0.5 + .5
55 return ''.join(["%.2x" % int(x * 256) for x in hls_to_rgb(hue, li, sat)]) 55 return ''.join(["%.2x" % int(x * 256) for x in hls_to_rgb(hue, li, sat)])
56 56
57 def graph_png(start, length): 57 def graph_png(start, length):
58 os.environ['MATT_PNG_BODGE_COMPRESS'] = '4'
59 os.environ['MATT_PNG_BODGE_FILTER'] = 'paeth'
58 rrds = all_sensors() 60 rrds = all_sensors()
59 61
60 graph_args = [] 62 graph_args = []
61 have_volts = False 63 have_volts = False
62 for n, (rrdfile, sensor) in enumerate(rrds): 64 for n, (rrdfile, sensor) in enumerate(rrds):
119 args += ['--right-axis', '10:-20', # matches the scalevolts CDEF above 121 args += ['--right-axis', '10:-20', # matches the scalevolts CDEF above
120 '--right-axis-format', '%.0lf', 122 '--right-axis-format', '%.0lf',
121 # '--right-axis-label', 'Temperature' 123 # '--right-axis-label', 'Temperature'
122 ] 124 ]
123 125
126 print>>sys.stderr, ' '.join("'%s'" % s for s in args)
124 rrdtool.graph(*args) 127 rrdtool.graph(*args)
128 #return tempf
125 return tempf.read() 129 return tempf.read()
126 130
127 def sensor_update(sensor_id, measurements, first_real_time, time_step): 131 def sensor_update(sensor_id, measurements, first_real_time, time_step):
128 try: 132 try:
129 open(sensor_rrd_path(sensor_id)) 133 open(sensor_rrd_path(sensor_id))
139 # XXX what to do here when it fails... 143 # XXX what to do here when it fails...
140 for v in values: 144 for v in values:
141 try: 145 try:
142 rrdtool.update(rrdfile, v) 146 rrdtool.update(rrdfile, v)
143 except rrdtool.error, e: 147 except rrdtool.error, e:
144 print>>sys.stderr, "Bad rrdtool update '%s'" % v 148 print>>sys.stderr, "Bad rrdtool update '%s': %s" % (v, str(e))
145 traceback.print_exc(file=sys.stderr) 149 traceback.print_exc(file=sys.stderr)
146 150
147 # be paranoid 151 # be paranoid
148 f = file(rrdfile) 152 #f = file(rrdfile)
149 os.fsync(f.fileno()) 153 #os.fsync(f.fileno())
150 154
151 def debug_file(mode='r'): 155 def debug_file(mode='r'):
152 return open('%s/debug.log' % config.DATA_PATH, mode) 156 return open('%s/debug.log' % config.DATA_PATH, mode)
153 157
154 def record_debug(lines): 158 def record_debug(lines):
176 tick_wake = int(entries['tick_wake']) + 1 180 tick_wake = int(entries['tick_wake']) + 1
177 tick_secs = int(entries['tick_secs']) 181 tick_secs = int(entries['tick_secs'])
178 return val_ticks + float(val_rem) * tick_secs / tick_wake 182 return val_ticks + float(val_rem) * tick_secs / tick_wake
179 183
180 def parse(lines): 184 def parse(lines):
185
186 start_time = time.time()
181 187
182 debugf = record_debug(lines) 188 debugf = record_debug(lines)
183 189
184 entries = dict(l.split('=', 1) for l in lines) 190 entries = dict(l.split('=', 1) for l in lines)
185 if len(entries) != len(lines): 191 if len(entries) != len(lines):
227 233
228 for sensor_id, measurements in zip(sensors, meas): 234 for sensor_id, measurements in zip(sensors, meas):
229 # XXX sqlite add 235 # XXX sqlite add
230 sensor_update(sensor_id, measurements, first_real_time, time_step) 236 sensor_update(sensor_id, measurements, first_real_time, time_step)
231 237
232 debugf.write("Updated %d sensors\n" % len(sensors)) 238 timedelta = time.time() - start_time
239 debugf.write("Updated %d sensors in %.2f secs\n" % (len(sensors), timedelta))
233 debugf.flush() 240 debugf.flush()