Last active
March 4, 2022 08:49
-
-
Save ulisesantana/9871f549207bf5adbd9c1f25d1c515c7 to your computer and use it in GitHub Desktop.
A simple OS Report function
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
export function osReport(os) { | |
const cpus = os.cpus() | |
const totalMemory = os.totalmem() | |
const freeMemory = os.freemem() | |
const usedMemory = totalMemory - freeMemory | |
return ` | |
Arch: ${os.arch} | |
CPUS: ${cpus.length} (${cpus[0].model} ${cpus[0].speed}) | |
Memory: ${fromBytesToGigabytes(usedMemory)}/${fromBytesToGigabytes(totalMemory)} | |
Platform: ${os.platform} | |
Release: ${os.release()} | |
Uptime: ${fromSecondsToHuman(os.uptime())} | |
` | |
} | |
function fromBytesToGigabytes(bytes) { | |
return `${(bytes / 1e9).toFixed(2)} GB` | |
} | |
function fromSecondsToHuman(seconds) { | |
return new Date(seconds * 1000).toISOString().substring(11,19) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment