diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-12-13 18:35:25 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2015-12-13 18:35:25 +0100 |
commit | 1318dab05f3c3b6c471e4919596744e889562034 (patch) | |
tree | 7ae2ecc693c769057c43e3da43706a4229289d03 | |
parent | 8ec05409b48181aec03119c2fb01fa1377d4837b (diff) | |
parent | 1ebd4c9030827857eb0c7f665324e18ceefbe1f5 (diff) | |
download | dabmux-1318dab05f3c3b6c471e4919596744e889562034.tar.gz dabmux-1318dab05f3c3b6c471e4919596744e889562034.tar.bz2 dabmux-1318dab05f3c3b6c471e4919596744e889562034.zip |
Merge remote-tracking branch 'yoann/next' into next
Fixes munin script and adds gui improvements
-rwxr-xr-x | doc/stats_dabmux_multi.py | 8 | ||||
-rw-r--r-- | gui/muxconfig.py | 50 | ||||
-rwxr-xr-x | gui/odr-dabmux-gui.py | 22 |
3 files changed, 52 insertions, 28 deletions
diff --git a/doc/stats_dabmux_multi.py b/doc/stats_dabmux_multi.py index a2587a4..05f52af 100755 --- a/doc/stats_dabmux_multi.py +++ b/doc/stats_dabmux_multi.py @@ -101,13 +101,13 @@ if len(sys.argv) == 1: munin_values = "" for ident in values: v = values[ident]['inputstat'] - munin_values += "multigraph buffers_{ident}\n".format(ident=ident) + munin_values += "multigraph buffers_{ident}\n".format(ident=ident.replace('-', '_')) munin_values += "high.value {}\n".format(v['max_fill']) munin_values += "low.value {}\n".format(v['min_fill']) - munin_values += "multigraph over_underruns_{ident}\n".format(ident=ident) + munin_values += "multigraph over_underruns_{ident}\n".format(ident=ident.replace('-', '_')) munin_values += "underruns.value {}\n".format(v['num_underruns']) munin_values += "overruns.value {}\n".format(v['num_overruns']) - munin_values += "multigraph audio_levels_{ident}\n".format(ident=ident) + munin_values += "multigraph audio_levels_{ident}\n".format(ident=ident.replace('-', '_')) munin_values += "left.value {}\n".format(v['peak_left']) munin_values += "right.value {}\n".format(v['peak_right']) @@ -123,7 +123,7 @@ elif len(sys.argv) == 2 and sys.argv[1] == "config": munin_config = config_top for conf in config['config']: - munin_config += config_template.format(ident=conf) + munin_config += config_template.format(ident=conf.replace('-', '_')) print(munin_config) else: diff --git a/gui/muxconfig.py b/gui/muxconfig.py index 4b307fd..35587f4 100644 --- a/gui/muxconfig.py +++ b/gui/muxconfig.py @@ -27,7 +27,8 @@ class General(object): """Container object for general options""" def __init__(self, pt): ptree = pt['general'] - for fieldname in ["nbframes", + for fieldname in [ + "nbframes", "statsserverport", "writescca", "tist", @@ -44,7 +45,8 @@ class Service(object): def __init__(self, name, ptree): self.name = name - for fieldname in ['id', + for fieldname in [ + "id", "label", "shortlabel", "pty", @@ -58,7 +60,8 @@ class Subchannel(object): """Container object for a subchannel""" def __init__(self, name, ptree): self.name = name - for fieldname in ['type', + for fieldname in [ + "type", "inputfile", "zmq-buffer", "zmq-prebuffering", @@ -97,20 +100,33 @@ class ConfigurationHandler(object): self._config = None self._statistics = None + #self._ctx = zmq.Context() + #self.sock = zmq.Socket(self._ctx, zmq.REQ) + #self.sock.setsockopt(zmq.LINGER, 0) + #self.sock.connect("tcp://{}:{}".format(self._host, self._port)) + + def zRead(self, key): self._ctx = zmq.Context() self.sock = zmq.Socket(self._ctx, zmq.REQ) + self.sock.setsockopt(zmq.LINGER, 0) self.sock.connect("tcp://{}:{}".format(self._host, self._port)) + self.sock.send(key) + + # use poll for timeouts: + poller = zmq.Poller() + poller.register(self.sock, zmq.POLLIN) + if poller.poll(5*1000): # 5s timeout in milliseconds + recv = self.sock.recv() + self.sock.close() + self._ctx.term() + return recv + else: + raise IOError("Timeout processing ZMQ request") def load(self): - """Load the configuration from the multiplexer and - save it locally""" - self.sock.send(b'info') - server_info = self.sock.recv() - - self.sock.send(b'getptree') - config_info = self.sock.recv() - - print("Config '%r'" % config_info) + """Load the configuration from the multiplexer and save it locally""" + server_info = self.zRead(b'info') + config_info = self.zRead(b'getptree') self._server_version = json.loads(server_info)['service'] self._config = json.loads(config_info) @@ -118,17 +134,13 @@ class ConfigurationHandler(object): def update_stats(self): """Load the statistics from the multiplexer and save them locally""" - - self.sock.send(b'info') - server_info = self.sock.recv() - - self.sock.send(b'values') - stats_info = self.sock.recv() + server_info = self.zRead(b'info') + stats_info = self.zRead(b'values') self._statistics = json.loads(stats_info)['values'] def get_full_configuration(self): - return json.dumps(self._config, indent=4) + return self._config def set_full_configuration(self, config_json): self.sock.send(b'setptree', flags=zmq.SNDMORE) diff --git a/gui/odr-dabmux-gui.py b/gui/odr-dabmux-gui.py index caa4ea7..85098f8 100755 --- a/gui/odr-dabmux-gui.py +++ b/gui/odr-dabmux-gui.py @@ -31,7 +31,7 @@ from muxconfig import * from bottle import route, run, template, static_file, request import json -conf = ConfigurationHandler('localhost') +import argparse @route('/config') def config(): @@ -63,7 +63,7 @@ def config_json_post(): return template('configeditor', version = conf.get_mux_version(), - config = conf.get_full_configuration(), + config = json.dumps(conf.get_full_configuration(), indent=4), message = successmessage) @route('/config.json', method="GET") @@ -73,8 +73,8 @@ def config_json_get(): conf.load() - return {'version': conf.get_mux_version(), - 'config': conf.get_full_configuration()} + return { 'version': conf.get_mux_version(), + 'config': conf.get_full_configuration() } @route('/') @@ -112,5 +112,17 @@ def stats_json(): def send_static(filename): return static_file(filename, root='./static') -run(host='localhost', port=8000, debug=True, reloader=True) + +if __name__ == '__main__': + # Get configuration file in argument + parser = argparse.ArgumentParser(description='management server for ODR-DabMux') + parser.add_argument('--host', default='127.0.0.1', help='socket host (default: 127.0.0.1)',required=False) + parser.add_argument('--port', default='8000', help='socket port (default: 8000)',required=False) + parser.add_argument('--mhost', default='127.0.0.1', help='mux host (default: 127.0.0.1)',required=False) + parser.add_argument('--mport', default='12720', help='mux port (default: 12720)',required=False) + cli_args = parser.parse_args() + + conf = ConfigurationHandler(cli_args.mhost, cli_args.mport) + + run(host=cli_args.host, port=int(cli_args.port), debug=True, reloader=False) |