From 752fa808e3f148f45b689a026f0e703c83b83d92 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sun, 15 Mar 2015 19:23:39 +0100 Subject: Add a statistics page to gui --- gui/muxconfig.py | 24 +++++++++++++++++++++++- gui/odr-dabmux-gui.py | 11 +++++++++++ gui/static/stats.js | 17 +++++++++++++++++ gui/views/stats.tpl | 20 ++++++++++++++++++++ 4 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 gui/static/stats.js create mode 100644 gui/views/stats.tpl (limited to 'gui') diff --git a/gui/muxconfig.py b/gui/muxconfig.py index 64321a2..f725462 100644 --- a/gui/muxconfig.py +++ b/gui/muxconfig.py @@ -95,6 +95,7 @@ class ConfigurationHandler(object): # local copy of the configuration self._server_version = None self._config = None + self._statistics = None def load(self): """Load the configuration from the multiplexer and @@ -102,14 +103,30 @@ class ConfigurationHandler(object): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((self._host, self._port)) - s.sendall(b'getptree\n') server_info = s.recv(32768) + s.sendall(b'getptree\n') config_info = s.recv(32768) s.close() self._server_version = json.loads(server_info.decode())['service'] self._config = json.loads(config_info.decode()) + def update_stats(self): + """Load the statistics from the multiplexer and + save them locally""" + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + + s.connect((self._host, self._port)) + server_info = s.recv(32768) + + s.sendall(b'values\n') + + stats_info = s.recv(32768) + s.close() + + print("STATS: {}".format(stats_info.decode())) + self._statistics = json.loads(stats_info.decode())['values'] + def get_full_configuration(self): return self._config @@ -130,3 +147,8 @@ class ConfigurationHandler(object): def get_general_options(self): return General(self._config) + + def get_stats_dict(self): + """Return a dictionary with all stats""" + self.update_stats() + return self._statistics diff --git a/gui/odr-dabmux-gui.py b/gui/odr-dabmux-gui.py index 84331b5..19f3ae8 100755 --- a/gui/odr-dabmux-gui.py +++ b/gui/odr-dabmux-gui.py @@ -62,6 +62,17 @@ def index(): version = conf.get_mux_version(), services = conf.get_services()) +@route('/stats') +def index(): + conf.load() + + return template('stats', + version = conf.get_mux_version()) + +@route('/stats.json') +def stats_json(): + return conf.get_stats_dict() + @route('/static/') def send_static(filename): diff --git a/gui/static/stats.js b/gui/static/stats.js new file mode 100644 index 0000000..7b07099 --- /dev/null +++ b/gui/static/stats.js @@ -0,0 +1,17 @@ +var updatefunc = function(event) { + $('#statdata p').remove(); + $.getJSON('/stats.json', function(result) { + $.each(result, function(name) { + // TODO: use a hidden template inside the DOM instead + // of building the HTML here + $("

") + .append(result[name]['inputstat']['num_underruns']) + .appendTo('#statdata'); + }); + }); +} + +// Handle clicks on the to change visiblity of panes +setInterval(updatefunc, 1000); + + diff --git a/gui/views/stats.tpl b/gui/views/stats.tpl new file mode 100644 index 0000000..30d82c5 --- /dev/null +++ b/gui/views/stats.tpl @@ -0,0 +1,20 @@ + + + + ODR-DabMux Statistics + + + + +

Subchannel stats for {{version}}

+ + Update + +
+

Subchannels

+
+
+ + + + -- cgit v1.2.3