1.1.0 • Published 5 months ago

memvigil v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

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

1.1.0

5 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago