From 4b093f6f432f097030a168ede4078eb243967607 Mon Sep 17 00:00:00 2001 From: peusterm Date: Fri, 19 May 2017 10:25:01 +0200 Subject: [PATCH] Fix/update: Simplified emulator dashboard that only shows running containers and DCs. No graph, since this does not work by non-dummy-gk deployments. Dashboard autoupdated itself every 2 s. --- src/emuvim/api/rest/rest_api_endpoint.py | 8 +++-- src/emuvim/dashboard/index_upb.html | 34 ++---------------- src/emuvim/dashboard/js/main_upb.js | 44 ++++++------------------ 3 files changed, 18 insertions(+), 68 deletions(-) diff --git a/src/emuvim/api/rest/rest_api_endpoint.py b/src/emuvim/api/rest/rest_api_endpoint.py index 891f95d..10b6c26 100755 --- a/src/emuvim/api/rest/rest_api_endpoint.py +++ b/src/emuvim/api/rest/rest_api_endpoint.py @@ -130,7 +130,11 @@ class RestApiEndpoint(object): logging.info("Started API endpoint @ http://%s:%d" % (self.ip, self.port)) def _start_flask(self): - #self.app.run(self.ip, self.port, debug=True, use_reloader=False) + #self.app.run(self.ip, self.port, debug=False, use_reloader=False) #this should be a more production-fit http-server - http_server = WSGIServer((self.ip, self.port), self.app) + #self.app.logger.setLevel(logging.ERROR) + http_server = WSGIServer((self.ip, self.port), + self.app, + log=open("/dev/null", "w") # This disables HTTP request logs to not mess up the CLI when e.g. the auto-updated dashboard is used + ) http_server.serve_forever() diff --git a/src/emuvim/dashboard/index_upb.html b/src/emuvim/dashboard/index_upb.html index 485a6b1..cbff5e0 100755 --- a/src/emuvim/dashboard/index_upb.html +++ b/src/emuvim/dashboard/index_upb.html @@ -25,7 +25,7 @@ - + @@ -48,36 +48,6 @@ -
@@ -103,7 +73,7 @@
- + diff --git a/src/emuvim/dashboard/js/main_upb.js b/src/emuvim/dashboard/js/main_upb.js index 0fb707d..619702f 100755 --- a/src/emuvim/dashboard/js/main_upb.js +++ b/src/emuvim/dashboard/js/main_upb.js @@ -1,18 +1,18 @@ -var API_HOST = "http://127.0.0.1:5001"; +var API_HOST = ""; // set to a remote url if dashboard is not served by REST API server var ERROR_ALERT = false; var TIMESTAMP = 0; var CONNECTED = false; var LATENESS_UPDATE_INTERVAL = 50; -var DATA_UPDATE_INTERVAL = 1000 * 10; +var DATA_UPDATE_INTERVAL = 1000 * 2; var LAST_UPDATE_TIMESTAMP_CONTAINER = 0; var LAST_UPDATE_TIMESTAMP_DATACENTER = 0; function update_lateness_loop() { lateness_datacenter= (Date.now() - LAST_UPDATE_TIMESTAMP_DATACENTER) / 1000; - $("#lbl_lateness_datacenter").text("Lateness: " + Number(lateness_datacenter).toPrecision(3) + "s"); + $("#lbl_lateness_datacenter").text("Lateness: " + Number(lateness_datacenter).toPrecision(2) + "s"); lateness_container= (Date.now() - LAST_UPDATE_TIMESTAMP_CONTAINER) / 1000; - $("#lbl_lateness_container").text("Lateness: " + Number(lateness_container).toPrecision(3) + "s"); + $("#lbl_lateness_container").text("Lateness: " + Number(lateness_container).toPrecision(2) + "s"); // loop while connected if(CONNECTED) setTimeout(update_lateness_loop, LATENESS_UPDATE_INTERVAL) @@ -26,11 +26,12 @@ function errorAjaxConnection() { ERROR_ALERT = true; // show message - alert("ERROR!\nAPI request failed.\n\n Please check the backend connection.", function() { + alert("API request failed. Is the emulator running?", function() { // callback ERROR_ALERT = false; }); } + CONNECTED = false; } @@ -106,14 +107,6 @@ function fetch_container() } -function fetch_d3graph() -{ - // do HTTP request and trigger gui update on success - var request_url = API_HOST + "/restapi/network/d3jsgraph"; - console.debug("fetching from: " + request_url); - //$.getJSON(request_url, update_graph); -} - function fetch_loop() { // only fetch if we are connected @@ -134,7 +127,7 @@ function connect() { console.info("connect()"); // get host address - API_HOST = "http://" + $("#text_api_host").val(); + //API_HOST = "http://" + $("#text_api_host").val(); console.debug("API address: " + API_HOST); // reset data LAST_UPDATE_TIMESTAMP_DATACENTER = Date.now(); @@ -144,36 +137,19 @@ function connect() update_lateness_loop(); // restart data fetch loop fetch_loop(); - // gui updates - $("#btn_disconnect").removeClass("disabled"); - $("#btn_connect").addClass("disabled"); -} - -function disconnect() -{ - console.info("disconnect()"); - CONNECTED = false; - // gui updates - $("#btn_connect").removeClass("disabled"); - $("#btn_disconnect").addClass("disabled"); } $(document).ready(function(){ console.info("document ready"); // setup global connection error handling - /* + $.ajaxSetup({ "error": errorAjaxConnection }); - // add listeners - $("#btn_connect").click(connect); - $("#btn_disconnect").click(disconnect); - */ - setTimeout(fetch_datacenter, 1000);//fetch_datacenter(); - setTimeout(fetch_container, 2000);//fetch_container(); - + // connect + connect(); // additional refresh on window focus $(window).focus(function () { -- 2.25.1