diff --git a/examples/stats.html b/examples/stats.html index 1acf4324..1e22832d 100644 --- a/examples/stats.html +++ b/examples/stats.html @@ -10,15 +10,31 @@ html, body { font-family: "Oxygen", sans-serif; } - .ct-chart * { + svg, .ct-chart * { overflow: visible; } + .ct-series-a .ct-line, + .ct-series-a .ct-point { + stroke: blue; + } + + .ct-series-b .ct-line, + .ct-series-b .ct-point { + stroke: green; + } +
-
+
-

0

+ +
0 peers 0 nodes
+ +
+
+
+ @@ -27,21 +43,29 @@ var stats = {slide: [0,0,0,0,0], peers: [0,0,0,0,0]}; setInterval(function(){ stats.show(); }, 1000 * 15); -stats.show = function(){ $.getJSON(url.value||(location.origin+'/gun/stats.radata'), function(data){ console.log(data) +stats.show = function(){ $.getJSON(url.value||(location.origin+'/gun/stats.radata'), function(data){ console.log(data); + $('#peers').text(data.peers.count); + $('#nodes').text(data.node.count); + var mb = data.memory.heapTotal / 1024 / 1024; stats.slide.push(mb); stats.slide = stats.slide.slice(1); - $(peers).text(data.peers.count); - var data = { + new Chartist.Line('.ct-mem', { // A labels array that can contain any sort of values labels: ['-1min', '-45s', '-30s', '-15s', '0'], // Our series array that contains series objects or in this case series data arrays series: [stats.slide] - }; + }, {fullWidth: true, low: 0, axisY: { + labelInterpolationFnc: function(v) { return v+'MB' } + }}); - // Create a new line chart object where as first parameter we pass in a selector - // that is resolving to our chart container element. The Second parameter - // is the actual data object. - new Chartist.Line('.ct-chart', data); + new Chartist.Line('.ct-cpu', { + // A labels array that can contain any sort of values + labels: ['-15min', '-5min', '1min'], + // Our series array that contains series objects or in this case series data arrays + series: [data.cpu.loadavg.reverse()] + }, {fullWidth: true, low: 0, axisY: { + labelInterpolationFnc: function(v) { return v+'cpu' } + }}); }) } stats.show(); diff --git a/gun.js b/gun.js index 3aec8afa..d61b8da5 100644 --- a/gun.js +++ b/gun.js @@ -2013,16 +2013,16 @@ var tomap = function(k,i,m){m(k,true)}; ;(function(){ + var message; + function each(peer){ mesh.say(message, peer) } mesh.say = function(msg, peer, o){ /* TODO: Plenty of performance optimizations that can be made just based off of ordering, and reducing function calls for cached writes. */ - if(!peer){ - Type.obj.map(opt.peers, function(peer){ - mesh.say(msg, peer); - }); + if(!peer){ message = msg; + Type.obj.map(opt.peers, each); return; } var tmp, wire = peer.wire || ((opt.wire) && opt.wire(peer)), msh, raw;// || open(peer, ctx); // TODO: Reopen! @@ -2126,10 +2126,9 @@ mesh.hi = function(peer){ var tmp = peer.wire || {}; if(peer.id || peer.url){ - Type.obj.del(opt.peers, tmp.pid); opt.peers[peer.url || peer.id] = peer; } else { - tmp = peer.id = peer.id || Type.text.random(9); + tmp = peer.id = tmp.pid = peer.id || Type.text.random(9); mesh.say({dam: '?'}, opt.peers[tmp] = peer); } if(!tmp.hied){ ctx.on(tmp.hied = 'hi', peer) } @@ -2155,8 +2154,10 @@ return; } if(!peer.wire){ return } - if(peer.wire.pid){ return } // they already set their ID! - peer.id = peer.wire.pid = msg.pid; + if(!peer.wire.pid){ return } // only run code below if wire.pid exists + Type.obj.del(opt.peers, peer.wire.pid || peer.id); + delete peer.wire.pid; + peer.id = msg.pid; mesh.hi(peer); } return mesh;