Skip to content

Commit

Permalink
further python3 patches
Browse files Browse the repository at this point in the history
  • Loading branch information
maparent committed Sep 21, 2017
1 parent 657da30 commit b74f691
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
14 changes: 7 additions & 7 deletions circusweb/namespace.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_stats(self, watchers=[], watchersWithPids=[],

for watcher_tuple in watchersWithPids:
watcher, encoded_endpoint = watcher_tuple
endpoint = b64decode(encoded_endpoint)
endpoint = b64decode(encoded_endpoint).decode("utf-8")
if watcher == "sockets":
sockets = yield gen.Task(controller.get_sockets,
endpoint=endpoint)
Expand All @@ -54,18 +54,18 @@ def get_stats(self, watchers=[], watchersWithPids=[],

@classmethod
def consume_stats(cls, watcher, pid, stat, stat_endpoint):
stat_endpoint_b64 = b64encode(stat_endpoint)
stat_endpoint_b64 = b64encode(stat_endpoint.encode('utf-8'))
for p in cls.participants[stat_endpoint]:
if watcher == 'sockets':
# if we get information about sockets and we explicitely
# requested them, send back the information.
if 'sockets' in p.watchersWithPids and 'fd' in stat:
p.emit('socket-stats-{fd}-{endpoint}'.format(
fd=stat['fd'], endpoint=stat_endpoint_b64),
fd=stat['fd'], endpoint=stat_endpoint_b64.decode('utf-8')),
**stat)
elif 'sockets' in p.watchers and 'addresses' in stat:
p.emit('socket-stats-{endpoint}'.format(
endpoint=stat_endpoint_b64), reads=stat['reads'],
endpoint=stat_endpoint_b64.decode('utf-8')), reads=stat['reads'],
adresses=stat['addresses'])
else:
available_watchers = p.watchers + p.watchersWithPids + \
Expand All @@ -75,20 +75,20 @@ def consume_stats(cls, watcher, pid, stat, stat_endpoint):
if (watcher == 'circus' and
stat.get('name', None) in available_watchers):
p.emit('stats-{watcher}-{endpoint}'.format(
watcher=stat['name'], endpoint=stat_endpoint_b64),
watcher=stat['name'], endpoint=stat_endpoint_b64.decode('utf-8')),
mem=stat['mem'], cpu=stat['cpu'], age=stat['age'])
else:
if pid is None: # means that it's the aggregation
p.emit('stats-{watcher}-{endpoint}'.format(
watcher=watcher, endpoint=stat_endpoint_b64),
watcher=watcher, endpoint=stat_endpoint_b64.decode('utf-8')),
mem=stat['mem'], cpu=stat['cpu'],
age=stat['age'])
else:
if watcher in p.watchersWithPids:
p.emit(
'stats-{watcher}-{pid}-{endpoint}'.format(
watcher=watcher, pid=pid,
endpoint=stat_endpoint_b64),
endpoint=stat_endpoint_b64.decode('utf-8')),
mem=stat['mem'],
cpu=stat['cpu'],
age=stat['age'])
4 changes: 2 additions & 2 deletions circusweb/stats_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, topics, loop, callback, context=None,
self.pubsub_socket = self.context.socket(zmq.SUB)
get_connection(self.pubsub_socket, self.endpoint, ssh_server)
for topic in self.topics:
self.pubsub_socket.setsockopt(zmq.SUBSCRIBE, topic)
self.pubsub_socket.setsockopt(zmq.SUBSCRIBE, topic.encode('utf-8'))
self.stream = ZMQStream(self.pubsub_socket, loop)
self.stream.on_recv(self.process_message)
self.callback = callback
Expand All @@ -36,7 +36,7 @@ def __exit__(self, exc_type, exc_value, traceback):
def process_message(self, msg):
topic, stat = msg

topic = topic.split('.')
topic = topic.decode('utf-8').split('.')
if len(topic) == 3:
__, watcher, subtopic = topic
self.callback(watcher, subtopic, json.loads(stat), self.endpoint)
Expand Down
2 changes: 1 addition & 1 deletion circusweb/templates/sockets.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@
watchers.push(['sockets', ${dumps(b64encode(controller.get_client(endpoint).stats_endpoint))}, ${dumps(b64encode(endpoint))}]);
stats_endpoints.push(${dumps(controller.get_client(endpoint).stats_endpoint)});
% endfor
supervise(socket, [], watchers, ${dumps(sockets.keys())}, stats_endpoints);
supervise(socket, [], watchers, ${dumps(list(sockets.keys()))}, stats_endpoints);
});
</script>

0 comments on commit b74f691

Please sign in to comment.