Skip to content

MemVigil is a lightweight Node.js library for real-time memory monitoring and leak detection, with automatic heap snapshots and event-driven alerts.

License

Notifications You must be signed in to change notification settings

Hensh99/memvigil

Repository files navigation

memvigil

A comprehensive Node.js memory management and monitoring library with real-time tracking capabilities.

npm npm version License

Table of Contents

Installation

npm install memvigil

Features

  • 🔍 Real-time memory monitoring
  • 📊 CPU usage tracking
  • 🚨 Automatic leak detection
  • 📸 Heap snapshot generation
  • ♻️ Garbage collection analysis
  • 📈 Performance metrics
  • 🎯 Custom threshold alerts

Quick Start

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);

Usage Examples

Basic Monitoring

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...]

Production Best Practices

  1. Appropriate Monitoring Intervals

    // Use longer intervals in production
    monitor.startMonitoring(30000); // 30 seconds
  2. Resource Management

    // Clean up old snapshots
    monitor.on('heapSnapshot', (filePath) => {
        // Keep only last 5 snapshots
        cleanupOldSnapshots(5);
    });
  3. Error Handling

    monitor.on('error', (error) => {
        logger.error('Memory monitor error:', error);
    });
  4. Performance Impact Monitoring

    setInterval(() => {
        const impact = monitor.getPerformanceImpact();
        if (impact > 100) { // If overhead exceeds 100ms
            monitor.stopMonitoring();
        }
    }, 60000);

License

MIT License - see LICENSE file for details

About

MemVigil is a lightweight Node.js library for real-time memory monitoring and leak detection, with automatic heap snapshots and event-driven alerts.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published