Simple monitoring and management

This commit is contained in:
Tony Garnock-Jones 2018-11-21 14:23:30 +00:00
parent b19c92f957
commit 1f852a72e7
3 changed files with 75 additions and 3 deletions

View File

@ -0,0 +1,7 @@
module.exports = {
entry: "./lib/monitor.js",
mode: "development",
externals: {
crypto: 'null'
},
};

View File

@ -14,11 +14,15 @@ import {
const server = Http.HttpServer(null, 8000);
const fs = require('fs');
assertion type ConnectionName(scope, id);
assertion type Connection(connId);
message type Request(connId, body);
message type Response(connId, body);
message type Disconnect(connId);
// Internal isolation
assertion type Envelope(scope, body);
@ -42,11 +46,24 @@ spawn named 'rootServer' {
assert :snapshot Http.Response(
reqId, 200, "OK", {"Content-type": "text/html"},
'<!DOCTYPE html>' + UI.htmlToString(
<div>
<p>Hello</p>
</div>
<html>
<head>
<meta charset="utf-8"></meta>
</head>
<body>
<script src="dist/monitor.js"></script>
</body>
</html>
));
}
during Http.Request($reqId, server, 'get', ['dist', $file], _, _) {
const contents = fs.readFileSync(__dirname + '/../dist/' + file);
assert :snapshot Http.Response(reqId, 200, "OK", {}, contents);
}
during Connection($name) assert Envelope('monitor', Connection(name));
on message Envelope('monitor', Disconnect($name)) send Disconnect(name);
}
spawn named 'websocketListener' {
@ -59,6 +76,7 @@ spawn named 'websocketListener' {
}
}
on message Response(name, $resp) send Http.DataOut(reqId, new Encoder().push(resp).contents());
stop on message Disconnect(name);
}
}
@ -76,6 +94,7 @@ spawn named 'tcpListener' {
}
}
on message Response(name, $resp) send Tcp.DataOut(id, new Encoder().push(resp).contents());
stop on message Disconnect(name);
}
}

View File

@ -0,0 +1,46 @@
"use strict";
const UI = activate require("@syndicate-lang/driver-browser-ui");
// @jsx UI.html
// @jsxFrag UI.htmlFragment
const { ToBroker, FromBroker, BrokerConnected } = activate require("./client");
assertion type ConnectionName(scope, id);
assertion type Connection(connId);
message type Disconnect(connId);
spawn {
const ui = new UI.Anchor();
assert ui.html('body',
<div id="main">
<h1>Broker monitor</h1>
<div id="scopes"></div>
</div>);
const url = (function () {
const u = new URL(document.location);
u.protocol = u.protocol.replace(/^http/, 'ws');
u.pathname = '/monitor';
return u.toString();
})();
during BrokerConnected(url) {
during FromBroker(url, Connection(ConnectionName($scope, _))) {
const ui = new UI.Anchor();
assert ui.html('#scopes',
<div class={`scope_${scope}`}>
<p>Scope: <tt>{scope}</tt></p>
<ul></ul>
</div>);
during FromBroker(url, Connection(ConnectionName(scope, $id))) {
const ui = new UI.Anchor();
assert ui.html(`#scopes div.scope_${scope} ul`,
<li>{id.toString()} <button class="disconnect">Disconnect</button></li>);
on message UI.UIEvent(ui.fragmentId, 'button.disconnect', 'click', _) {
send ToBroker(url, Disconnect(ConnectionName(scope, id)));
}
}
}
}
}