forked from weaveworks/weave
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wgraph2.html
105 lines (92 loc) · 2.57 KB
/
wgraph2.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!doctype html>
<html>
<head>
<title>Weave Network</title>
<script type="text/javascript" src="http://visjs.org/dist/vis.js"></script>
<script src="jquery.js"></script>
<link href="http://visjs.org/dist/vis.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#mynetwork {
width: 1200px;
height: 800px;
border: 1px solid lightgray;
}
</style>
<script type="text/javascript">
var nodes = null;
var edges = null;
var network = null;
function destroy() {
if (network !== null) {
network.destroy();
network = null;
}
}
function create() {
destroy();
nodes = new vis.DataSet();
edges = new vis.DataSet();
// create a network
var container = document.getElementById('mynetwork');
var data = {
nodes: nodes,
edges: edges
};
var options = {
physics: {barnesHut: {gravitationalConstant: -5000, springLength: 200}}
};
//var options = { configurePhysics:true }
var network = new vis.Network(container, data, options);
}
function update() {
reverse_edges = {};
peers_now = {};
$.getJSON("http://" + ipaddr.value + ":6784/status-json", function(data) {
$.each(data.Peers.sort(function(a,b){return a.Name.localeCompare(b.Name);}), function(x, peer) {
id = "P"+peer.Name
nodes.update({
id: id,
label: "Peer " + x,
title: peer.Name,
group: "peers"
});
peers_now[id] = 1
$.each(peer.Connections, function(y, conn) {
from = peer.Name
to = conn.RemoteName
if (reverse_edges[from+to] != 1) {
edges.update({ id:to+from, from: "P"+from, to: "P"+to });
reverse_edges[to+from] = 1
}
});
});
$.each(data.Macs, function(x, mac) {
nodes.update({
id: "C"+mac.Mac,
label: "C",
title: mac.Mac,
group: "container"
});
edges.update({id: mac.Mac, from: "P"+mac.PeerName, to: "C"+mac.Mac, length: 40})
});
nodes.forEach(function(node) {
if (node.group == "peers" && !peers_now[node.id])
nodes.remove(node.id);
});
});
}
</script>
</head>
<body onload="create();setInterval(update, 1000);">
<section>
A rendering of the weave network, using visjs
<br>
<input id="loadbtn" type="button" value="reload" onclick="update();" />
Monitor endpoint: <input id="ipaddr" type="text" value="localhost"/>
</section>
<br>
<div id="mynetwork"></div>
<p id="selection"></p>
<p id="stabilization"></p>
</body>
</html>