- Improved "health check" for WebSocket

This commit is contained in:
Exodus4D
2017-01-21 23:21:25 +01:00
parent 07c0127e92
commit 378203f582
6 changed files with 81 additions and 15 deletions

View File

@@ -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);
}
/**

View File

@@ -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]',

View File

@@ -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'
}
});

View File

@@ -32,7 +32,6 @@ define([
// load info (maintenance) info panel (if scheduled)
$('body').loadPageStructure();
// show app information in browser console
Util.showVersionInfo();

View File

@@ -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'
}
});

View File

@@ -819,7 +819,7 @@
<repeat group="{{ @socketInformation }}" key="{{ @socketType }}" value="{{ @socketData }}">
<div class="col-xs-12 col-md-6 pf-landing-pricing-panel">
<div id="pf-setup-{{ @socketType }}" class="panel panel-default pricing-big" style="position: relative">
<div id="pf-setup-{{ @socketType }}" data-token="{{ @socketData.token }}" class="panel panel-default pricing-big" style="position: relative">
<div class="panel-heading text-left">
<h3 class="panel-title">{{ @socketData.label }}</h3>
</div>
@@ -852,10 +852,10 @@
<div class="panel-footer text-align-center">
<check if="{{ @socketData.online }}">
<true>
<h3 class="panel-title txt-color txt-color-success">CONNECTED</h3>
<h3 class="panel-title txt-color txt-color-success">PING SEND</h3>
</true>
<false>
<h3 class="panel-title txt-color txt-color-danger">CONNECTION FAILED</h3>
<h3 class="panel-title txt-color txt-color-danger">INIT CONNECTION...</h3>
</false>
</check>
</div>