Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Support cross-realm monitoring (#9)
Browse files Browse the repository at this point in the history
Support connecting to multiple brokers and displaying all the devices on
a single graph.

This relies on cross-realm auth having been set up between the F+
instances.
  • Loading branch information
amrc-benmorrow authored Mar 14, 2024
2 parents 5723183 + 8aaaf8c commit 6f31cc8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public/webpack/
/keytabs/
/volumes/

# Random tempdir
/tmp/

# IDE
.idea/
/public/output.css
9 changes: 7 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@
<input class="fpl-input" id="password" type="password" size="50">
</label>

<div class="text-xs text-gray-400">These credentials will need to have global debugger rights to see much
of interest.
<div class="text-xs text-gray-400">
<p>These credentials will need to have global debugger
rights to see much of interest.
<p>To monitor multiple brokers at the same time, give a
space-separated list of Directory URLs. The username
will need to be the full Kerberos principal name of
an account with cross-realm access to all the brokers.
</div>

<label class="text-gray-500 font-medium flex items-center">
Expand Down
48 changes: 31 additions & 17 deletions public/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,45 @@ class FPlusVis {
window.addEventListener("resize", resize);
resize();

const fplus = await new FactoryPlus.ServiceClient({
directory_url: opts.directory,
username: opts.username,
password: opts.password,
verbose: "ALL",
browser: true,
}).init();
window.AMRC_FactoryPlus_Vis_Client = fplus;
const graph = MQTTClient.graph("Factory+");
const clients = await this.build_clients(opts, graph);
this.clients = clients;
window.AMRC_FactoryPlus_Vis_Clients = clients;

const fplus = clients[0].fplus;
const icons = await new Icons({ fplus }).init();
const vis = this.vis = new Vis(graph, canvas, icons);

vis.run();
for (const { mqtt } of clients) {
mqtt.on("packet", vis.make_active.bind(vis));
mqtt.on("graph", vis.reset_graph.bind(vis));
mqtt.on("schema", u => icons.request_icon(u));
mqtt.run();
}
}

const mqtt = this.mqtt = new MQTTClient({
fplus, icons,
name: "Factory+",
});
const vis = this.vis = new Vis(mqtt.graph, canvas, icons).run();
async build_clients (opts, graph) {
const directories = opts.directory.split(/\s+/);
const { username, password } = opts;

mqtt.on("packet", vis.make_active.bind(vis));
mqtt.on("graph", vis.reset_graph.bind(vis));
return Promise.all(directories.map(async directory_url => {
const fplus = await new FactoryPlus.ServiceClient({
directory_url, username, password,
verbose: "ALL",
browser: true,
}).init();
const mqtt = new MQTTClient({ fplus, graph });

mqtt.run();
return { fplus, mqtt };
}));
}

async stop_vis () {
await this.vis.stop();
await this.mqtt.stop();
for (const { mqtt } of this.clients) {
await mqtt.stop();
}
this.canvas.style.display = "none";
}

Expand Down
14 changes: 9 additions & 5 deletions public/mqttclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ export default class MQTTClient extends EventEmitter {
constructor (opts) {
super();
this.fplus = opts.fplus;
this.icons = opts.icons;
this.graph = opts.graph;

this.known = new Map();
this.graph = {
name: opts.name,
}

static graph (name) {
return {
name,
online: true,
};
}
Expand All @@ -35,6 +38,7 @@ export default class MQTTClient extends EventEmitter {

stop () {
clearInterval(this.expiry_timer);
if (!this.mqtt) return;
return new Promise((resolve, reject) => {
this.mqtt.on("end", resolve);
this.mqtt.end();
Expand Down Expand Up @@ -116,7 +120,7 @@ export default class MQTTClient extends EventEmitter {

//console.log("Found schema %s for %s", schema, node.name);
node.schema = schema;
this.icons.request_icon(schema);
this.emit("schema", schema);
}

async check_directory (address, node) {
Expand All @@ -134,7 +138,7 @@ export default class MQTTClient extends EventEmitter {
if (node.seen_birth) return;

node.schema = info.top_schema;
this.icons.request_icon(node.schema);
this.emit("schema", node.schema);
}

on_expiry () {
Expand Down

0 comments on commit 6f31cc8

Please sign in to comment.