Added traffic delta functions.
This commit is contained in:
parent
a25ce3c0db
commit
56d0f2aafc
|
@ -572,7 +572,6 @@
|
|||
<Content Include="views\player.handlebars" />
|
||||
<Content Include="views\sharing.handlebars" />
|
||||
<Content Include="views\ssh.handlebars" />
|
||||
<Content Include="views\terminal.handlebars" />
|
||||
<Content Include="views\terms-mobile.handlebars" />
|
||||
<Content Include="views\terms.handlebars" />
|
||||
<Content Include="views\xterm.handlebars" />
|
||||
|
|
20
meshuser.js
20
meshuser.js
|
@ -905,7 +905,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||
|
||||
switch (cmd) {
|
||||
case 'help': {
|
||||
var fin = '', f = '', availcommands = 'help,maintenance,info,versions,resetserver,usersessions,closeusersessions,tasklimiter,setmaxtasks,cores,migrationagents,agentstats,agentissues,webstats,trafficstats,mpsstats,swarmstats,acceleratorsstats,updatecheck,serverupdate,nodeconfig,heapdump,relays,autobackup,backupconfig,dupagents,dispatchtable,badlogins,showpaths,le,lecheck,leevents,dbstats,dbcounters,sms,amtacm,certhashes,watchdog,amtmanager,amtpasswords,certexpire';
|
||||
var fin = '', f = '', availcommands = 'help,maintenance,info,versions,resetserver,usersessions,closeusersessions,tasklimiter,setmaxtasks,cores,migrationagents,agentstats,agentissues,webstats,trafficstats,trafficdelta,mpsstats,swarmstats,acceleratorsstats,updatecheck,serverupdate,nodeconfig,heapdump,relays,autobackup,backupconfig,dupagents,dispatchtable,badlogins,showpaths,le,lecheck,leevents,dbstats,dbcounters,sms,amtacm,certhashes,watchdog,amtmanager,amtpasswords,certexpire';
|
||||
if (parent.parent.config.settings.heapdump === true) { availcommands += ',heapdump'; }
|
||||
availcommands = availcommands.split(',').sort();
|
||||
while (availcommands.length > 0) { if (f.length > 80) { fin += (f + ',\r\n'); f = ''; } f += (((f != '') ? ', ' : ' ') + availcommands.shift()); }
|
||||
|
@ -1120,6 +1120,14 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||
}
|
||||
break;
|
||||
}
|
||||
case 'trafficdelta': {
|
||||
const stats = parent.getTrafficDelta(obj.trafficStats);
|
||||
obj.trafficStats = stats.current;
|
||||
for (var i in stats.delta) {
|
||||
if (typeof stats.delta[i] == 'object') { r += (i + ': ' + JSON.stringify(stats.delta[i]) + '\r\n'); } else { r += (i + ': ' + stats.delta[i] + '\r\n'); }
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'watchdog': {
|
||||
if (parent.parent.watchdog == null) {
|
||||
r = 'Server watchdog not active.';
|
||||
|
@ -5823,6 +5831,16 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||
});
|
||||
break;
|
||||
}
|
||||
case 'trafficstats': {
|
||||
try { ws.send(JSON.stringify({ action: 'trafficstats', stats: parent.getTrafficStats() })); } catch (ex) { }
|
||||
break;
|
||||
}
|
||||
case 'trafficdelta': {
|
||||
const stats = parent.getTrafficDelta(obj.trafficStats);
|
||||
obj.trafficStats = stats.current;
|
||||
try { ws.send(JSON.stringify({ action: 'trafficdelta', delta: stats.delta })); } catch (ex) { }
|
||||
break;
|
||||
}
|
||||
case 'getDeviceDetails': {
|
||||
if (common.validateStrArray(command.nodeids, 1) == false) break; // Check nodeids
|
||||
if (common.validateString(command.type, 3, 4) == false) break; // Check type
|
||||
|
|
17
webserver.js
17
webserver.js
|
@ -361,7 +361,24 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
|
|||
CIRAIn: 0,
|
||||
CIRAOut: 0
|
||||
}
|
||||
obj.trafficStats.time = Date.now();
|
||||
obj.getTrafficStats = function () { return obj.trafficStats; }
|
||||
obj.getTrafficDelta = function (oldTraffic) { // Return the difference between the old and new data along with the delta time.
|
||||
const data = obj.common.Clone(obj.trafficStats);
|
||||
data.time = Date.now();
|
||||
const delta = calcDelta(oldTraffic ? oldTraffic : {}, data);
|
||||
if (oldTraffic && oldTraffic.time) { delta.delta = (data.time - oldTraffic.time); }
|
||||
delta.time = data.time;
|
||||
return { current: data, delta: delta }
|
||||
}
|
||||
function calcDelta(oldData, newData) { // Recursive function that computes the difference of all numbers
|
||||
const r = {};
|
||||
for (var i in newData) {
|
||||
if (typeof newData[i] == 'object') { r[i] = calcDelta(oldData[i] ? oldData[i] : {}, newData[i]); }
|
||||
if (typeof newData[i] == 'number') { if (typeof oldData[i] == 'number') { r[i] = (newData[i] - oldData[i]); } else { r[i] = newData[i]; } }
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// Keep a record of the last agent issues.
|
||||
obj.getAgentIssues = function () { return obj.agentIssues; }
|
||||
|
|
Loading…
Reference in New Issue