Created
December 28, 2017 16:06
-
-
Save shanewholloway/6a216bb4e27bf02f101bfa4816427a89 to your computer and use it in GitHub Desktop.
NodeJS snippet for periodically showing memory use over time
This file contains hidden or 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
function show_memory(interval=1000) { | |
setTimeout(show_memory, interval).unref() | |
let out = [] | |
const mem = process.memoryUsage() | |
out.push('MEM') | |
for (const [k,v] of Object.entries(mem)) { | |
out.push(`${k}: ${(v / 1.0e6).toFixed(1)} MB`) | |
} | |
const cpu = process.cpuUsage() | |
out.push(' CPU') | |
for (const [k,v] of Object.entries(cpu)) { | |
out.push(`${k}: ${(v / 1.0e6).toFixed(2)}s`) | |
} | |
out.push(`up ${process.uptime()}s`) | |
console.log('### %s', out.join(' ')) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment