is it possible to trigger the node.js dump before the linux kernel oom event

36 views Asked by At

I have a node.js (version 16.20.2) application always kill by linux OOM killer, is it possible to dump the node.js memory before the OOM killed event? I already add the dump logical and exposed the dump as a rest api:

router.get('/dump', (req, res) => {
  const snapshotStream = v8.getHeapSnapshot()
  // It's important that the filename end with `.heapsnapshot`,
  // otherwise Chrome DevTools won't open it.
  const fileName = `/opt/data/y-websocket-dump/${Date.now()}.heapsnapshot`
  const fileStream = fs.createWriteStream(fileName)
  snapshotStream.pipe(fileStream)

  res.send('ok')
})

I just need to dump before the linux OOM killed events. and analysis the memory leak with the dump file. is it possible?

0

There are 0 answers