diff --git a/examples/stats.html b/examples/stats.html index 382888dc..ca0187c9 100644 --- a/examples/stats.html +++ b/examples/stats.html @@ -47,16 +47,17 @@ var fetchData = async function(){ // fetch the data from server var data = await (await fetch(url.value||(location.origin+'/gun/stats.radata'), {method: 'GET',mode: 'cors'})).json(); + data.over = (data.over/1000) || 15; $('#peers').text(data.peers.count); $('#time').text((data.peers.time / 1000 / 60).toFixed(0)); $('#nodes').text(data.node.count); $('#hours').text((data.up.time / 60 / 60).toFixed(1)); Stats('memory').line.append(+new Date, data.memory.heapTotal / 1024 / 1024); - try{ Stats('dam # in').line.append(+new Date, data.dam.in.count); }catch(e){} - try{ Stats('dam in MB').line.append(+new Date, data.dam.in.done / 1024 / 1024); }catch(e){} - try{ Stats('dam # out').line.append(+new Date, data.dam.out.count); }catch(e){} - try{ Stats('dam out MB').line.append(+new Date, data.dam.out.done / 1024 / 1024); }catch(e){} + try{ Stats('dam # in/s').line.append(+new Date, Math.round(data.dam.in.count / data.over)); }catch(e){} + try{ Stats('dam in MB/s').line.append(+new Date, data.dam.in.done / 1024 / 1024 / data.over); }catch(e){} + try{ Stats('dam # out/s').line.append(+new Date, Math.round(data.dam.out.count / data.over)); }catch(e){} + try{ Stats('dam out MB/s').line.append(+new Date, data.dam.out.done / 1024 / 1024 / data.over); }catch(e){} console.log('data',data); //fetch keys in all, these may be dynamically changing diff --git a/lib/stats.js b/lib/stats.js index bfd4cc1e..ff7d834d 100644 --- a/lib/stats.js +++ b/lib/stats.js @@ -26,11 +26,13 @@ Gun.on('opt', function(root){ root.stats.up.count = (root.stats.up.count || 0) + 1; root.stats.stay = root.stats.stay || {}; root.stats.gap = {}; + root.stats.over = +new Date; },1); setInterval(function(){ - var S = +new Date; if(!root.stats){ root.stats = {} } + var S = +new Date; var stats = root.stats, tmp; + stats.over = S - (stats.over||S); (stats.up||{}).time = process.uptime(); stats.memory = process.memoryUsage() || {}; stats.memory.totalmem = os.totalmem(); @@ -44,19 +46,24 @@ Gun.on('opt', function(root){ stats.all = all; var dam = root.opt.mesh; if(dam){ - stats.dam = {'in': {count: dam.hear.c, done: dam.hear.d, long: dam.hear.long}, 'out': {count: dam.say.c, done: dam.say.d}}; + stats.dam = {'in': {count: dam.hear.c, done: dam.hear.d}, 'out': {count: dam.say.c, done: dam.say.d}}; dam.hear.c = dam.hear.d = dam.say.c = dam.say.d = 0; // reset stats.peers.time = dam.bye.time || 0; - dam.hear.long = []; } var rad = root.opt.store; rad = rad && rad.stats; if(rad){ stats.rad = rad; root.opt.store.stats = {get:{time:{}, count:0}, put: {time:{}, count:0}}; // reset } - console.STAT && console.STAT(S, +new Date - S, 'stats'); S = +new Date; - - fs.writeFile(__dirname+'/../stats.'+root.opt.file, JSON.stringify(stats, null, 2), function(err){ console.STAT && console.STAT(S, +new Date - S, 'stats stash') }); + console.STAT && console.STAT(S, +new Date - S, 'stats'); + S = +new Date; + //fs.writeFile(__dirname+'/../stats.'+root.opt.file, JSON.stringify(stats, null, 2), function(err){ console.STAT && console.STAT(S, +new Date - S, 'stats stash') }); + // TEMPORARY TEST TO SEE HOW SLOW/FAST FS IS!!! + fs.writeFileSync(__dirname+'/../stats.'+root.opt.file, JSON.stringify(stats, null, 2)); + console.log("[[[[[[[[[[", +new Date - S, "]]]]]]]]]]"); + // TEMPORARY TEST TO SEE HOW SLOW/FAST FS IS!!! + console.STAT && console.STAT(S, +new Date - S, 'stats stash'); + stats.over = +new Date; stats.gap = {}; }, 1000 * 15); Object.keys = Object.keys || function(o){ return Gun.obj.map(o, function(v,k,t){t(k)}) }