Memory Monitor

Automatic memory monitoring with leak detection.

1 min readEdit this page

Usage

import { MemoryMonitor } from '@restjs/memory'
 
const monitor = new MemoryMonitor({
  intervalMs: 30000,
  warnThresholdPercent: 70,
  criticalThresholdPercent: 85,
  autoFix: true,
  onLeak: (leaks) => logger.warn('Leaks', { count: leaks.length }),
  onCritical: (snap) => logger.error('Critical', { mb: snap.heapUsedMb })
})
 
monitor.start()

Manual scan

const report = await monitor.scan()
report.status   // 'clean' | 'leaks-fixed' | 'critical'
report.freedMb