Skip to content

Instantly share code, notes, and snippets.

@ulisesantana
Last active March 4, 2022 08:49
Show Gist options
  • Save ulisesantana/9871f549207bf5adbd9c1f25d1c515c7 to your computer and use it in GitHub Desktop.
Save ulisesantana/9871f549207bf5adbd9c1f25d1c515c7 to your computer and use it in GitHub Desktop.
A simple OS Report function
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