A comprehensive Node.js memory management and monitoring library with real-time tracking capabilities.
npm install memvigil
- 🔍 Real-time memory monitoring
- 📊 CPU usage tracking
- 🚨 Automatic leak detection
- 📸 Heap snapshot generation
- ♻️ Garbage collection analysis
- 📈 Performance metrics
- 🎯 Custom threshold alerts
const MemoryMonitor = require('memvigil');
// Initialize with 200MB threshold
const monitor = new MemoryMonitor(200 * 1024 * 1024);
// Set up basic event listeners
monitor.on('thresholdExceeded', (memoryUsage) => {
console.log('Memory threshold exceeded:',
`${(memoryUsage.heapUsed / 1024 / 1024).toFixed(2)}MB`);
});
monitor.on('leakDetected', (details) => {
console.log('Memory leak detected:', details.message);
console.log('Suggestions:', details.suggestions);
});
// Start monitoring with 10-second intervals
monitor.startMonitoring(10000);
const MemoryMonitor = require('memvigil');
// Initialize with 200MB threshold
const monitor = new MemoryMonitor(200 * 1024 * 1024);
// Start monitoring with 10-second intervals
monitor.startMonitoring(10000);
[Rest of the existing usage examples remain the same...]
-
Appropriate Monitoring Intervals
// Use longer intervals in production monitor.startMonitoring(30000); // 30 seconds
-
Resource Management
// Clean up old snapshots monitor.on('heapSnapshot', (filePath) => { // Keep only last 5 snapshots cleanupOldSnapshots(5); });
-
Error Handling
monitor.on('error', (error) => { logger.error('Memory monitor error:', error); });
-
Performance Impact Monitoring
setInterval(() => { const impact = monitor.getPerformanceImpact(); if (impact > 100) { // If overhead exceeds 100ms monitor.stopMonitoring(); } }, 60000);
MIT License - see LICENSE file for details