annotate bin/collector @ 1595:013cbd7a0f08

choice-type attrs in live Ignore-this: 6c762ec4b8f93c4700edbb080990eb5f
author Drew Perttula <drewp@bigasterisk.com>
date Sat, 03 Jun 2017 09:20:04 +0000
parents 8268224c1b23
children 7d5d6e7bc526
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
1 #!bin/python
1590
8268224c1b23 WIP support for choice/enum attrs
drewp@bigasterisk.com
parents: 1564
diff changeset
2 """
8268224c1b23 WIP support for choice/enum attrs
drewp@bigasterisk.com
parents: 1564
diff changeset
3 Collector receives device attrs from multiple senders, combines
8268224c1b23 WIP support for choice/enum attrs
drewp@bigasterisk.com
parents: 1564
diff changeset
4 them, and sends output attrs to hardware. The combining part has
8268224c1b23 WIP support for choice/enum attrs
drewp@bigasterisk.com
parents: 1564
diff changeset
5 custom code for some attributes.
8268224c1b23 WIP support for choice/enum attrs
drewp@bigasterisk.com
parents: 1564
diff changeset
6
8268224c1b23 WIP support for choice/enum attrs
drewp@bigasterisk.com
parents: 1564
diff changeset
7 Input can be over http or zmq.
8268224c1b23 WIP support for choice/enum attrs
drewp@bigasterisk.com
parents: 1564
diff changeset
8 """
8268224c1b23 WIP support for choice/enum attrs
drewp@bigasterisk.com
parents: 1564
diff changeset
9
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
10 from __future__ import division
1541
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
11 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
12 from twisted.internet import reactor, utils
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
13 from txzmq import ZmqEndpoint, ZmqFactory, ZmqPullConnection
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
14 import json
1289
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
15 import logging
1372
f427801da9f6 collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents: 1307
diff changeset
16 import optparse
1541
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
17 import time
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
18 import traceback
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
19 import cyclone.web, cyclone.websocket
1289
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
20 from greplin import scales
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
21
1289
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
22 from run_local import log
1541
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
23 from lib.cycloneerr import PrettyErrorHandler
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
24 from light9.collector.output import EnttecDmx, Udmx
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
1307
8863b4485fd4 collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents: 1289
diff changeset
28 from light9.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
1491
c0742e710eeb refactor collector json parsing
drewp@bigasterisk.com
parents: 1490
diff changeset
31 def parseJsonMessage(msg):
1492
ce97f298bfb8 restore zmq transport to collector
drewp@bigasterisk.com
parents: 1491
diff changeset
32 body = json.loads(msg)
1491
c0742e710eeb refactor collector json parsing
drewp@bigasterisk.com
parents: 1490
diff changeset
33 settings = []
c0742e710eeb refactor collector json parsing
drewp@bigasterisk.com
parents: 1490
diff changeset
34 for device, attr, value in body['settings']:
1595
013cbd7a0f08 choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents: 1590
diff changeset
35 if isinstance(value, basestring) and value.startswith('http'):
013cbd7a0f08 choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents: 1590
diff changeset
36 value = URIRef(value)
013cbd7a0f08 choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents: 1590
diff changeset
37 else:
013cbd7a0f08 choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents: 1590
diff changeset
38 value = Literal(value)
013cbd7a0f08 choice-type attrs in live
Drew Perttula <drewp@bigasterisk.com>
parents: 1590
diff changeset
39 settings.append((URIRef(device), URIRef(attr), value))
1491
c0742e710eeb refactor collector json parsing
drewp@bigasterisk.com
parents: 1490
diff changeset
40 return body['client'], body['clientSession'], settings, body['sendTime']
c0742e710eeb refactor collector json parsing
drewp@bigasterisk.com
parents: 1490
diff changeset
41
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
42 def startZmq(port, collector):
1289
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
43 stats = scales.collection('/zmqServer',
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
44 scales.PmfStat('setAttr'))
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
45
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
46 zf = ZmqFactory()
1492
ce97f298bfb8 restore zmq transport to collector
drewp@bigasterisk.com
parents: 1491
diff changeset
47 addr = 'tcp://*:%s' % port
ce97f298bfb8 restore zmq transport to collector
drewp@bigasterisk.com
parents: 1491
diff changeset
48 log.info('creating zmq endpoint at %r', addr)
ce97f298bfb8 restore zmq transport to collector
drewp@bigasterisk.com
parents: 1491
diff changeset
49 e = ZmqEndpoint('bind', addr)
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
50 s = ZmqPullConnection(zf, e)
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
51 def onPull(message):
1492
ce97f298bfb8 restore zmq transport to collector
drewp@bigasterisk.com
parents: 1491
diff changeset
52 with stats.setAttr.time():
1289
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
53 # todo: new compressed protocol where you send all URIs up
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
54 # front and then use small ints to refer to devices and
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
55 # attributes in subsequent requests.
1492
ce97f298bfb8 restore zmq transport to collector
drewp@bigasterisk.com
parents: 1491
diff changeset
56 client, clientSession, settings, sendTime = parseJsonMessage(message[0])
ce97f298bfb8 restore zmq transport to collector
drewp@bigasterisk.com
parents: 1491
diff changeset
57 collector.setAttrs(client, clientSession, settings, sendTime)
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
58 s.onPull = onPull
1289
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
59
1541
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
60 class WebListeners(object):
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
61 def __init__(self):
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
62 self.clients = []
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
63
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
64 def addClient(self, client):
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
65 self.clients.append([client, {}])
1543
c8cffe82b537 collector gui updates
Drew Perttula <drewp@bigasterisk.com>
parents: 1541
diff changeset
66 log.info('added client %s', client)
1541
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
67
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
68 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
69 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
70 log.info('delClient %s, %s left', client, len(self.clients))
1541
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
71
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
72 def outputAttrsSet(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
73 now = time.time()
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
74
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
75 msg = self.makeMsg(dev, attrs, outputMap)
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
76
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
77 # this omits repeats, but can still send many
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
78 # messages/sec. Not sure if piling up messages for the browser
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
79 # could lead to slowdowns in the real dmx output.
1541
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
80 for client, seen in self.clients:
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
81 for m, t in seen.items():
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
82 if t < now - 5:
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
83 del seen[m]
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
84 if msg in seen:
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
85 continue
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
86 seen[msg] = now
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
87 client.sendMessage(msg)
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
88
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
89 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
90 attrRows = []
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
91 for attr, val in attrs.items():
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
92 output, index = outputMap[(dev, attr)]
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
93 attrRows.append({'attr': attr.rsplit('/')[-1],
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
94 'val': val,
1543
c8cffe82b537 collector gui updates
Drew Perttula <drewp@bigasterisk.com>
parents: 1541
diff changeset
95 'chan': (output.shortId(), index + 1)})
1541
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
96 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
97 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
98 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
99
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
100 msg = json.dumps({'outputAttrsSet': {'dev': dev, 'attrs': attrRows}}, sort_keys=True)
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
101 return msg
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
102
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
103 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
104
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
105 def connectionMade(self, *args, **kwargs):
1543
c8cffe82b537 collector gui updates
Drew Perttula <drewp@bigasterisk.com>
parents: 1541
diff changeset
106 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
107 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
108
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
109 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
110 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
111
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
112 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
113 json.loads(message)
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
114
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
115 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
116
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
117 class Attrs(PrettyErrorHandler, cyclone.web.RequestHandler):
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
118 def put(self):
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
119 with stats.setAttr.time():
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
120 client, clientSession, settings, sendTime = parseJsonMessage(self.request.body)
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
121 self.settings.collector.setAttrs(client, clientSession, settings, sendTime)
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
122 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
123
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
124
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
125
1490
649d482737e0 start of a collector --loadtest mode
Drew Perttula <drewp@bigasterisk.com>
parents: 1489
diff changeset
126 def launch(graph, doLoadTest=False):
1530
a5a44077c54c docs and error msgs
drewp@bigasterisk.com
parents: 1493
diff changeset
127 try:
a5a44077c54c docs and error msgs
drewp@bigasterisk.com
parents: 1493
diff changeset
128 # todo: drive outputs with config files
a5a44077c54c docs and error msgs
drewp@bigasterisk.com
parents: 1493
diff changeset
129 outputs = [
a5a44077c54c docs and error msgs
drewp@bigasterisk.com
parents: 1493
diff changeset
130 #EnttecDmx(L9['output/dmx0/'], '/dev/dmx0', 80),
a5a44077c54c docs and error msgs
drewp@bigasterisk.com
parents: 1493
diff changeset
131 Udmx(L9['output/udmx/'], 510),
a5a44077c54c docs and error msgs
drewp@bigasterisk.com
parents: 1493
diff changeset
132 ]
a5a44077c54c docs and error msgs
drewp@bigasterisk.com
parents: 1493
diff changeset
133 except Exception as e:
a5a44077c54c docs and error msgs
drewp@bigasterisk.com
parents: 1493
diff changeset
134 log.error("setting up outputs: %r", e)
a5a44077c54c docs and error msgs
drewp@bigasterisk.com
parents: 1493
diff changeset
135 traceback.print_exc()
a5a44077c54c docs and error msgs
drewp@bigasterisk.com
parents: 1493
diff changeset
136 raise
1541
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
137 listeners = WebListeners()
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
138 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
139
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
140 startZmq(networking.collectorZmq.port, c)
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
141
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
142 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
143 cyclone.web.Application(handlers=[
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
144 (r'/()', cyclone.web.StaticFileHandler,
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
145 {"path" : "light9/collector/web", "default_filename" : "index.html"}),
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
146 (r'/updates', Updates),
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
147 (r'/attrs', Attrs),
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
148 (r'/stats', StatsForCyclone),
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
149 ], collector=c, listeners=listeners),
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
150 interface='::')
1289
5a4e74f1e36a Fixed client session clearing bugs.
Drew Perttula <drewp@bigasterisk.com>
parents: 1288
diff changeset
151 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
152 networking.collectorZmq.port)
1490
649d482737e0 start of a collector --loadtest mode
Drew Perttula <drewp@bigasterisk.com>
parents: 1489
diff changeset
153 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
154 # 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
155 # 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
156 # 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
157 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
158 log.info('running collector_loadtest')
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
159 d = utils.getProcessValue('bin/python', ['bin/collector_loadtest.py'])
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
160 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
161 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
162 reactor.stop()
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
163 d.addCallback(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
164 reactor.callLater(2, afterWarmup)
1307
8863b4485fd4 collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents: 1289
diff changeset
165
8863b4485fd4 collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents: 1289
diff changeset
166 def main():
1372
f427801da9f6 collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents: 1307
diff changeset
167 parser = optparse.OptionParser()
f427801da9f6 collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents: 1307
diff changeset
168 parser.add_option("-v", "--verbose", action="store_true",
f427801da9f6 collector properly merges repeated attr settings in the same message
Drew Perttula <drewp@bigasterisk.com>
parents: 1307
diff changeset
169 help="logging.DEBUG")
1490
649d482737e0 start of a collector --loadtest mode
Drew Perttula <drewp@bigasterisk.com>
parents: 1489
diff changeset
170 parser.add_option("--loadtest", action="store_true",
649d482737e0 start of a collector --loadtest mode
Drew Perttula <drewp@bigasterisk.com>
parents: 1489
diff changeset
171 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
172 (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
173 log.setLevel(logging.DEBUG if options.verbose else logging.INFO)
1307
8863b4485fd4 collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents: 1289
diff changeset
174
8863b4485fd4 collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents: 1289
diff changeset
175 graph = SyncedGraph(networking.rdfdb.url, "collector")
8863b4485fd4 collector uses rdfdb
Drew Perttula <drewp@bigasterisk.com>
parents: 1289
diff changeset
176
1541
c1bf296b0a74 collector uses cyclone and gets a web ui showing output attrs
Drew Perttula <drewp@bigasterisk.com>
parents: 1530
diff changeset
177 graph.initiallySynced.addCallback(lambda _: launch(graph, options.loadtest)).addErrback(log.error)
1288
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
178 reactor.run()
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
179
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
180 if __name__ == '__main__':
5e76c8fd8a03 rewrite dmx outputter to a new service
Drew Perttula <drewp@bigasterisk.com>
parents:
diff changeset
181 main()