summaryrefslogtreecommitdiffstats
path: root/gui
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2015-03-15 19:23:39 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2015-06-19 10:26:02 +0200
commit752fa808e3f148f45b689a026f0e703c83b83d92 (patch)
tree3347c04c69e65a1945a3da1f9d61f9c441169611 /gui
parentc31a5cab786b79dc781f80fa3f9dae8376a2ed84 (diff)
downloaddabmux-752fa808e3f148f45b689a026f0e703c83b83d92.tar.gz
dabmux-752fa808e3f148f45b689a026f0e703c83b83d92.tar.bz2
dabmux-752fa808e3f148f45b689a026f0e703c83b83d92.zip
Add a statistics page to gui
Diffstat (limited to 'gui')
-rw-r--r--gui/muxconfig.py24
-rwxr-xr-xgui/odr-dabmux-gui.py11
-rw-r--r--gui/static/stats.js17
-rw-r--r--gui/views/stats.tpl20
4 files changed, 71 insertions, 1 deletions
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/<filename:path>')
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
+ $("<p></p>")
+ .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 @@
+<!DOCTYPE html>
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
+ <title>ODR-DabMux Statistics</title>
+ <link rel="stylesheet" href="static/style.css" type="text/css" media="screen" charset="utf-8"/>
+ <script type="text/javascript" src="static/jquery-1.7.1.min.js"></script>
+</head>
+<body>
+ <h1>Subchannel stats for {{version}}</h1>
+
+ <a id="update">Update</a>
+
+ <div id="subchannels">
+ <p>Subchannels</p>
+ <div id="statdata"></div>
+ </div>
+ <script type="text/javascript" src="static/stats.js"></script>
+</body>
+</html>
+