Mercurial > code > home > repos > light9
annotate bin/collector @ 1864:375f48d1518a
mypy, flake8 setups
Ignore-this: 159ab09780ff33dec508d2d25c1628bf
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Sat, 25 May 2019 12:03:26 +0000 |
parents | 40cc863d2b63 |
children | 3c523c71da29 |
rev | line source |
---|---|
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
1 #!bin/python |
1590 | 2 """ |
3 Collector receives device attrs from multiple senders, combines | |
4 them, and sends output attrs to hardware. The combining part has | |
5 custom code for some attributes. | |
6 | |
7 Input can be over http or zmq. | |
8 """ | |
9 | |
1697
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1692
diff
changeset
|
10 from run_local import log |
5c04a54df635
fix startup (this might be breaking mypy)
Drew Perttula <drewp@bigasterisk.com>
parents:
1692
diff
changeset
|
11 |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
12 from rdflib import URIRef, Literal |
1493
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
13 from twisted.internet import reactor, utils |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
14 from txzmq import ZmqEndpoint, ZmqFactory, ZmqPullConnection |
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
15 import json |
1289
5a4e74f1e36a
Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents:
1288
diff
changeset
|
16 import logging |
1372
f427801da9f6
collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents:
1307
diff
changeset
|
17 import optparse |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
18 import time |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
19 import traceback |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
20 import cyclone.web, cyclone.websocket |
1289
5a4e74f1e36a
Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents:
1288
diff
changeset
|
21 from greplin import scales |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
22 |
1861 | 23 from cycloneerr import PrettyErrorHandler |
1605 | 24 from light9.collector.output import EnttecDmx, Udmx, DummyOutput |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
25 from light9.collector.collector import Collector |
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
26 from light9.namespaces import L9 |
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
27 from light9 import networking |
1692 | 28 from rdfdb.syncedgraph import SyncedGraph |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
29 from light9.greplin_cyclone import StatsForCyclone |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
30 |
1858 | 31 |
1491 | 32 def parseJsonMessage(msg): |
1492 | 33 body = json.loads(msg) |
1491 | 34 settings = [] |
35 for device, attr, value in body['settings']: | |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
36 if isinstance(value, str) and value.startswith('http'): |
1595
013cbd7a0f08
choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents:
1590
diff
changeset
|
37 value = URIRef(value) |
013cbd7a0f08
choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents:
1590
diff
changeset
|
38 else: |
013cbd7a0f08
choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents:
1590
diff
changeset
|
39 value = Literal(value) |
013cbd7a0f08
choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents:
1590
diff
changeset
|
40 settings.append((URIRef(device), URIRef(attr), value)) |
1491 | 41 return body['client'], body['clientSession'], settings, body['sendTime'] |
42 | |
1858 | 43 |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
44 def startZmq(port, collector): |
1858 | 45 stats = scales.collection('/zmqServer', scales.PmfStat('setAttr')) |
46 | |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
47 zf = ZmqFactory() |
1492 | 48 addr = 'tcp://*:%s' % port |
49 log.info('creating zmq endpoint at %r', addr) | |
50 e = ZmqEndpoint('bind', addr) | |
1858 | 51 |
1809
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
52 class Pull(ZmqPullConnection): |
1826
d6ec468112cb
not sure highwatermark setting did what i wanted
drewp@bigasterisk.com
parents:
1822
diff
changeset
|
53 #highWaterMark = 3 |
1809
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
54 def onPull(self, message): |
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
55 with stats.setAttr.time(): |
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
56 # todo: new compressed protocol where you send all URIs up |
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
57 # front and then use small ints to refer to devices and |
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
58 # attributes in subsequent requests. |
1858 | 59 client, clientSession, settings, sendTime = parseJsonMessage( |
60 message[0]) | |
1809
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
61 collector.setAttrs(client, clientSession, settings, sendTime) |
1858 | 62 |
1809
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
63 s = Pull(zf, e) |
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
64 |
1289
5a4e74f1e36a
Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents:
1288
diff
changeset
|
65 |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
66 class WebListeners(object): |
1858 | 67 |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
68 def __init__(self): |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
69 self.clients = [] |
1858 | 70 self.pendingMessageForDev = {} # dev: (attrs, outputmap) |
1596
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
71 self.lastFlush = 0 |
1858 | 72 |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
73 def addClient(self, client): |
1858 | 74 self.clients.append([client, {}]) # seen = {dev: attrs} |
1806
5668ad92a98e
bug in collector log
Drew Perttula <drewp@bigasterisk.com>
parents:
1801
diff
changeset
|
75 log.info('added client %s %s', len(self.clients), client) |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
76 |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
77 def delClient(self, client): |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
78 self.clients = [[c, t] for c, t in self.clients if c != client] |
1543
c8cffe82b537
collector gui updates
Drew Perttula <drewp@bigasterisk.com>
parents:
1541
diff
changeset
|
79 log.info('delClient %s, %s left', client, len(self.clients)) |
1858 | 80 |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
81 def outputAttrsSet(self, dev, attrs, outputMap): |
1596
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
82 """called often- don't be slow""" |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
83 |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
84 self.pendingMessageForDev[dev] = (attrs, outputMap) |
1809
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
85 try: |
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
86 self._flush() |
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
87 except Exception: |
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
88 traceback.print_exc() |
778c67ab70c9
set zmq highWaterMark to dump stale messages, especially those sent when collector isn't running
drewp@bigasterisk.com
parents:
1806
diff
changeset
|
89 raise |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
90 |
1596
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
91 def _flush(self): |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
92 now = time.time() |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
93 if now < self.lastFlush + .05 or not self.clients: |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
94 return |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
95 self.lastFlush = now |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
96 |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
97 while self.pendingMessageForDev: |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
98 dev, (attrs, outputMap) = self.pendingMessageForDev.popitem() |
1564
f2e6d96d02de
minor comments and refactors, I think, except the removal of 'row update' logging made a big perf difference
Drew Perttula <drewp@bigasterisk.com>
parents:
1543
diff
changeset
|
99 |
1858 | 100 msg = None # lazy, since makeMsg is slow |
101 | |
1596
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
102 # this omits repeats, but can still send many |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
103 # messages/sec. Not sure if piling up messages for the browser |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
104 # could lead to slowdowns in the real dmx output. |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
105 for client, seen in self.clients: |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
106 if seen.get(dev) == attrs: |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
107 continue |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
108 if msg is None: |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
109 msg = self.makeMsg(dev, attrs, outputMap) |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
110 |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
111 seen[dev] = attrs |
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
112 client.sendMessage(msg) |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
113 |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
114 def makeMsg(self, dev, attrs, outputMap): |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
115 attrRows = [] |
1859
f066d6e874db
2to3 with these fixers: all idioms set_literal
drewp@bigasterisk.com
parents:
1858
diff
changeset
|
116 for attr, val in list(attrs.items()): |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
117 output, index = outputMap[(dev, attr)] |
1858 | 118 attrRows.append({ |
119 'attr': attr.rsplit('/')[-1], | |
120 'val': val, | |
121 'chan': (output.shortId(), index + 1) | |
122 }) | |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
123 attrRows.sort(key=lambda r: r['chan']) |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
124 for row in attrRows: |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
125 row['chan'] = '%s %s' % (row['chan'][0], row['chan'][1]) |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
126 |
1858 | 127 msg = json.dumps({'outputAttrsSet': { |
128 'dev': dev, | |
129 'attrs': attrRows | |
130 }}, | |
131 sort_keys=True) | |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
132 return msg |
1858 | 133 |
134 | |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
135 class Updates(cyclone.websocket.WebSocketHandler): |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
136 |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
137 def connectionMade(self, *args, **kwargs): |
1543
c8cffe82b537
collector gui updates
Drew Perttula <drewp@bigasterisk.com>
parents:
1541
diff
changeset
|
138 log.info('socket connect %s', self) |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
139 self.settings.listeners.addClient(self) |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
140 |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
141 def connectionLost(self, reason): |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
142 self.settings.listeners.delClient(self) |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
143 |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
144 def messageReceived(self, message): |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
145 json.loads(message) |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
146 |
1858 | 147 |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
148 stats = scales.collection('/webServer', scales.PmfStat('setAttr')) |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
149 |
1858 | 150 |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
151 class Attrs(PrettyErrorHandler, cyclone.web.RequestHandler): |
1858 | 152 |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
153 def put(self): |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
154 with stats.setAttr.time(): |
1858 | 155 client, clientSession, settings, sendTime = parseJsonMessage( |
156 self.request.body) | |
157 self.settings.collector.setAttrs(client, clientSession, settings, | |
158 sendTime) | |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
159 self.set_status(202) |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
160 |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
161 |
1490
649d482737e0
start of a collector --loadtest mode
Drew Perttula <drewp@bigasterisk.com>
parents:
1489
diff
changeset
|
162 def launch(graph, doLoadTest=False): |
1530 | 163 try: |
164 # todo: drive outputs with config files | |
165 outputs = [ | |
1822 | 166 # EnttecDmx(L9['output/dmxA/'], '/dev/dmx3', 80), |
1858 | 167 Udmx(L9['output/dmxA/'], bus=5, numChannels=80), |
1822 | 168 #DummyOutput(L9['output/dmxA/'], 80), |
169 Udmx(L9['output/dmxB/'], bus=7, numChannels=500), | |
1530 | 170 ] |
1799
0bb7b9df12e5
collector warnings and errors. the reactor.crash isn't working.
drewp@bigasterisk.com
parents:
1798
diff
changeset
|
171 except Exception: |
0bb7b9df12e5
collector warnings and errors. the reactor.crash isn't working.
drewp@bigasterisk.com
parents:
1798
diff
changeset
|
172 log.error("setting up outputs:") |
1530 | 173 traceback.print_exc() |
174 raise | |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
175 listeners = WebListeners() |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
176 c = Collector(graph, outputs, listeners) |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
177 |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
178 startZmq(networking.collectorZmq.port, c) |
1858 | 179 |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
180 reactor.listenTCP(networking.collector.port, |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
181 cyclone.web.Application(handlers=[ |
1858 | 182 (r'/()', cyclone.web.StaticFileHandler, { |
183 "path": "light9/collector/web", | |
184 "default_filename": "index.html" | |
185 }), | |
1541
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
186 (r'/updates', Updates), |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
187 (r'/attrs', Attrs), |
c1bf296b0a74
collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents:
1530
diff
changeset
|
188 (r'/stats', StatsForCyclone), |
1858 | 189 ], |
190 collector=c, | |
191 listeners=listeners), | |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
192 interface='::') |
1289
5a4e74f1e36a
Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents:
1288
diff
changeset
|
193 log.info('serving http on %s, zmq on %s', networking.collector.port, |
5a4e74f1e36a
Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents:
1288
diff
changeset
|
194 networking.collectorZmq.port) |
1490
649d482737e0
start of a collector --loadtest mode
Drew Perttula <drewp@bigasterisk.com>
parents:
1489
diff
changeset
|
195 if doLoadTest: |
1493
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
196 # in a subprocess since we don't want this client to be |
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
197 # cooperating with the main event loop and only sending |
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
198 # requests when there's free time |
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
199 def afterWarmup(): |
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
200 log.info('running collector_loadtest') |
1858 | 201 d = utils.getProcessValue('bin/python', |
202 ['bin/collector_loadtest.py']) | |
203 | |
1493
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
204 def done(*a): |
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
205 log.info('loadtest done') |
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
206 reactor.stop() |
1858 | 207 |
1493
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
208 d.addCallback(done) |
1858 | 209 |
1493
4294ed82ee16
move collector_loadtest and arrange for collector to be able to run the test itself, but that last part isn't working. you can run collector and collector_loadtest in two shells, though
drewp@bigasterisk.com
parents:
1492
diff
changeset
|
210 reactor.callLater(2, afterWarmup) |
1858 | 211 |
212 | |
1307
8863b4485fd4
collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1289
diff
changeset
|
213 def main(): |
1372
f427801da9f6
collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents:
1307
diff
changeset
|
214 parser = optparse.OptionParser() |
1858 | 215 parser.add_option("-v", |
216 "--verbose", | |
217 action="store_true", | |
1372
f427801da9f6
collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents:
1307
diff
changeset
|
218 help="logging.DEBUG") |
1858 | 219 parser.add_option("--loadtest", |
220 action="store_true", | |
1490
649d482737e0
start of a collector --loadtest mode
Drew Perttula <drewp@bigasterisk.com>
parents:
1489
diff
changeset
|
221 help="call myself with some synthetic load then exit") |
1372
f427801da9f6
collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents:
1307
diff
changeset
|
222 (options, args) = parser.parse_args() |
f427801da9f6
collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents:
1307
diff
changeset
|
223 log.setLevel(logging.DEBUG if options.verbose else logging.INFO) |
1307
8863b4485fd4
collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1289
diff
changeset
|
224 |
1596
7d5d6e7bc526
collector web view speedups- don't json encode all devs all the time
Drew Perttula <drewp@bigasterisk.com>
parents:
1595
diff
changeset
|
225 logging.getLogger('colormath').setLevel(logging.INFO) |
1858 | 226 |
1307
8863b4485fd4
collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1289
diff
changeset
|
227 graph = SyncedGraph(networking.rdfdb.url, "collector") |
8863b4485fd4
collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents:
1289
diff
changeset
|
228 |
1858 | 229 graph.initiallySynced.addCallback(lambda _: launch(graph, options.loadtest) |
230 ).addErrback(lambda e: reactor.crash()) | |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
231 reactor.run() |
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
232 |
1858 | 233 |
1288
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
234 if __name__ == '__main__': |
5e76c8fd8a03
rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff
changeset
|
235 main() |