Skip to content

Instantly share code, notes, and snippets.

@spinscale
Created March 25, 2024 09:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spinscale/4fb56aa781fdcd16d632acbfa2d15ac2 to your computer and use it in GitHub Desktop.
Save spinscale/4fb56aa781fdcd16d632acbfa2d15ac2 to your computer and use it in GitHub Desktop.
node.js cronjob to dump memory stats every second
const memoryCronJob = new CronJob("* * * * * *", async () => {
const formatMemoryUsage = (data : number) => `${Math.round(data / 1024 / 1024 * 100) / 100} MB`;
const memoryData = process.memoryUsage();
const memoryUsage = {
rss: `${formatMemoryUsage(memoryData.rss)} -> Resident Set Size - total memory allocated for the process execution`,
heapTotal: `${formatMemoryUsage(memoryData.heapTotal)} -> total size of the allocated heap`,
heapUsed: `${formatMemoryUsage(memoryData.heapUsed)} -> actual memory used during the execution`,
external: `${formatMemoryUsage(memoryData.external)} -> V8 external memory`,
};
console.log(memoryUsage);
})
memoryCronJob.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment