Skip to content

Instantly share code, notes, and snippets.

@janez89
Last active August 29, 2015 14:05
Show Gist options
  • Save janez89/08f9e87f0a066bdf477d to your computer and use it in GitHub Desktop.
Save janez89/08f9e87f0a066bdf477d to your computer and use it in GitHub Desktop.
NodeJS - formated system tools
/**
* @author Janez89
*/
module.exports = {
// get uptime in day, hour, min, sec format
uptime: function (uptime){
if (typeof uptime === undefined)
uptime = process.uptime();
var time = {};
time.day = parseInt( uptime /60 /60 /24 );
time.hour = parseInt( uptime /60 /60 %24 );
time.min = parseInt( uptime /60 %60 );
time.sec = parseInt( uptime %60 );
return time;
},
// get load avg with 2 decimal precise
loadAvg: function () {
var load = require('os').loadavg();
return [
Math.round(load[0] * 100) / 100 ,
Math.round(load[1] * 100) / 100 ,
Math.round(load[2] * 100) / 100
];
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment