From 378203f582fe342a152f538c9cc491f361a12982 Mon Sep 17 00:00:00 2001 From: Exodus4D Date: Sat, 21 Jan 2017 23:21:25 +0100 Subject: [PATCH] - Improved "health check" for WebSocket --- app/main/controller/controller.php | 7 +++--- app/main/controller/setup.php | 10 +++++++-- js/app/setup.js | 36 +++++++++++++++++++++++++++--- public/js/v1.2.0/app/mappage.js | 1 - public/js/v1.2.0/app/setup.js | 36 +++++++++++++++++++++++++++--- public/templates/view/setup.html | 6 ++--- 6 files changed, 81 insertions(+), 15 deletions(-) diff --git a/app/main/controller/controller.php b/app/main/controller/controller.php index 6c174b68..9fb13064 100644 --- a/app/main/controller/controller.php +++ b/app/main/controller/controller.php @@ -808,13 +808,14 @@ class Controller { return Config::getEnvironmentData($key); } + /** * health check for ICP socket -> ping request * @param $ttl - * @return bool|string + * @param $load */ - static function checkTcpSocket($ttl){ - return (new Socket( Config::getSocketUri(), $ttl ))->sendData('healthCheck'); + static function checkTcpSocket($ttl, $load){ + (new Socket( Config::getSocketUri(), $ttl ))->sendData('healthCheck', $load); } /** diff --git a/app/main/controller/setup.php b/app/main/controller/setup.php index d702b29b..414be18f 100644 --- a/app/main/controller/setup.php +++ b/app/main/controller/setup.php @@ -946,10 +946,15 @@ class Setup extends Controller { // $ttl for health check $ttl = 600; + $heachCheckToken = microtime(true); + + // ping TCP Socket with checkToken + self::checkTcpSocket($ttl, $heachCheckToken); + $socketInformation = [ 'tcpSocket' => [ 'label' => 'Socket (intern) [TCP]', - 'online' => (self::checkTcpSocket($ttl) == 'OK'), + 'online' => true, 'data' => [ [ 'label' => 'HOST', @@ -968,7 +973,8 @@ class Setup extends Controller { 'value' => $ttl, 'check' => !empty( $ttl ) ] - ] + ], + 'token' => $heachCheckToken ], 'webSocket' => [ 'label' => 'WebSocket (clients) [HTTP]', diff --git a/js/app/setup.js b/js/app/setup.js index d6c32146..ee369454 100644 --- a/js/app/setup.js +++ b/js/app/setup.js @@ -44,6 +44,7 @@ define([ * perform a basic check if Clients (browser) can connect to the webSocket server */ let testWebSocket = () => { + let tcpSocketPanel = $('#pf-setup-tcpSocket'); let webSocketPanel = $('#pf-setup-webSocket'); let WebSocketURI = MapWorker.getWebSocketURL(); @@ -96,18 +97,47 @@ define([ socket.onopen = (e) => { updateWebSocketPanel({ status: { - label: 'CONNECTED', - class: 'txt-color-success' + label: 'OPEN wait for response...', + class: 'txt-color-warning' } }); + // sent token and check response + socket.send(JSON.stringify({ + task: 'healthCheck', + load: tcpSocketPanel.data('token') + })); + webSocketPanel.hideLoadingAnimation(); }; + socket.onmessage = (e) => { + let response = JSON.parse(e.data); + + if(response === 1){ + // SUCCESS + updateWebSocketPanel({ + status: { + label: 'CONNECTED', + class: 'txt-color-success' + } + }); + }else{ + // Got response but INVALID + updateWebSocketPanel({ + status: { + label: 'INVALID RESPONSE', + class: 'txt-color-warning' + } + }); + } + + }; + socket.onerror = (e) => { updateWebSocketPanel({ status: { - label: 'CONNECTION FAILED', + label: 'CONNECTION ERROR', class: 'txt-color-danger' } }); diff --git a/public/js/v1.2.0/app/mappage.js b/public/js/v1.2.0/app/mappage.js index 2d8b26e6..5d4429c8 100644 --- a/public/js/v1.2.0/app/mappage.js +++ b/public/js/v1.2.0/app/mappage.js @@ -32,7 +32,6 @@ define([ // load info (maintenance) info panel (if scheduled) $('body').loadPageStructure(); - // show app information in browser console Util.showVersionInfo(); diff --git a/public/js/v1.2.0/app/setup.js b/public/js/v1.2.0/app/setup.js index d6c32146..ee369454 100644 --- a/public/js/v1.2.0/app/setup.js +++ b/public/js/v1.2.0/app/setup.js @@ -44,6 +44,7 @@ define([ * perform a basic check if Clients (browser) can connect to the webSocket server */ let testWebSocket = () => { + let tcpSocketPanel = $('#pf-setup-tcpSocket'); let webSocketPanel = $('#pf-setup-webSocket'); let WebSocketURI = MapWorker.getWebSocketURL(); @@ -96,18 +97,47 @@ define([ socket.onopen = (e) => { updateWebSocketPanel({ status: { - label: 'CONNECTED', - class: 'txt-color-success' + label: 'OPEN wait for response...', + class: 'txt-color-warning' } }); + // sent token and check response + socket.send(JSON.stringify({ + task: 'healthCheck', + load: tcpSocketPanel.data('token') + })); + webSocketPanel.hideLoadingAnimation(); }; + socket.onmessage = (e) => { + let response = JSON.parse(e.data); + + if(response === 1){ + // SUCCESS + updateWebSocketPanel({ + status: { + label: 'CONNECTED', + class: 'txt-color-success' + } + }); + }else{ + // Got response but INVALID + updateWebSocketPanel({ + status: { + label: 'INVALID RESPONSE', + class: 'txt-color-warning' + } + }); + } + + }; + socket.onerror = (e) => { updateWebSocketPanel({ status: { - label: 'CONNECTION FAILED', + label: 'CONNECTION ERROR', class: 'txt-color-danger' } }); diff --git a/public/templates/view/setup.html b/public/templates/view/setup.html index 25148f0e..63753411 100644 --- a/public/templates/view/setup.html +++ b/public/templates/view/setup.html @@ -819,7 +819,7 @@
-
+

{{ @socketData.label }}

@@ -852,10 +852,10 @@