Skip to content

Instantly share code, notes, and snippets.

@hackjoy
Last active Feb 21, 2021
Embed
What would you like to do?
Generate a heapdump file for analysis
router.post(
'/heapdump-4E5AB3A6ECC24CD5B413A6D4DB5DB02FB4907018',
auth(config.server.authToken),
asyncHandler(async (req, res, next) => {
const { logger } = dependencies;
const hostname = os.hostname();
const filepath = '/tmp/';
const filename = `${Date.now()}.heapsnapshot`;
try {
heapdump.writeSnapshot(filepath + filename, err => {
if (err) {
throw err;
}
logger.info('Generated heapdump: ' + filename);
const s3 = new S3();
const upload = new S3.ManagedUpload({
service: s3,
params: {
Bucket: 'engineering',
Key: `heapdump/some-service/${hostname}/${filename}`,
Body: fs.createReadStream(filepath + filename)
}
});
upload.send(err => {
if (err) {
logger.error('Error uploading', { err });
throw err;
}
logger.info(`Uploaded heapdump: ${filename}`);
res.sendStatus(200);
});
});
} catch (e) {
logger.error(e);
res.sendStatus(500);
}
})
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment