Last active
August 29, 2015 14:05
-
-
Save janez89/08f9e87f0a066bdf477d to your computer and use it in GitHub Desktop.
NodeJS - formated system tools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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