A Node.js application for monitoring system resources including CPU, memory, network, and process information with logging capabilities.
- Real-time System Monitoring: Continuously monitors system resources at configurable intervals
- Comprehensive Metrics Collection: Tracks CPU usage, memory consumption, network interfaces, and process information
- Advanced Logging: Built-in logging system with file persistence and console output
- Alert System: Automatic warning and error notifications for high resource usage
- Detailed Reporting: Generates summary reports of system performance and monitoring statistics
- Graceful Shutdown: Proper cleanup and report generation on application termination
- Clone the repository:
git clone <repository-url>
cd custom-logger.js
- Install dependencies:
npm install
- Run the application:
node custom-logger.js
The system monitor starts automatically when the script is executed. It will:
- Create a
logs
directory for storing monitoring data - Begin monitoring system resources every 3 seconds
- Display real-time metrics in the console
- Log all events to
./logs/system-monitor.log
- Generate a summary report on shutdown (saved as
monitor-report.txt
)
Press Ctrl+C
to gracefully shutdown the application.
- Memory Usage: Total, used, and free memory with percentage utilization
- CPU Information: Number of cores, model, load average, and usage percentage
- Process Metrics: Current process memory usage and uptime
- System Information: Platform, architecture, hostname, and user information
- Network Interfaces: Count and details of available network interfaces
The system automatically generates alerts based on resource usage:
-
Memory Usage:
- Warning: Above 70%
- Critical: Above 85%
-
CPU Usage:
- Warning: Above 60%
- Critical: Above 80%
Logs are stored in ./logs/system-monitor.log
with the following format:
2024-01-01T12:00:00.000Z [LEVEL] Message content
Where LEVEL
can be:
INFO
: General information and metricsWARN
: Warning alertsERROR
: Critical alerts
The monitoring interval can be adjusted by modifying the parameter in:
monitor.startMonitoring(3000); // 3000ms = 3 seconds
- Node.js
- File system write permissions for log directory creation