pms_md
v1.0.7
Published
Comprehensive monitoring solution for Node.js applications with error tracking, health checks, multi-database support (MongoDB, PostgreSQL, MySQL, MSSQL, SQLite, Redis, Cassandra, Elasticsearch, DynamoDB, Neo4j, CouchDB), and multi-channel notifications
Downloads
410
Maintainers
Readme
🚀 PMS_MD - Comprehensive Node.js Monitoring Solution
Production-ready monitoring solution for Node.js applications with comprehensive database support, error tracking, health checks, and multi-channel notifications.
✨ Features
- 🎨 Beautiful UI Dashboard - One-line integration with stunning monitoring UI (NEW!)
- 🗄️ 13+ Database Support - MongoDB, PostgreSQL, MySQL, MariaDB, MSSQL, SQLite, Redis, Cassandra, Elasticsearch, DynamoDB, Neo4j, CouchDB, Sequelize
- 📧 Email Notifications - Automatic alerts for errors, crashes, and database failures
- 📊 Health Monitoring - System resources (CPU, Memory), API errors, database connections
- 🔔 Multi-Channel Alerts - Email, Slack, and custom webhooks
- 📝 Advanced Logging - Winston-based logging with daily rotation and sanitization
- 🛡️ Graceful Shutdown - Proper cleanup with email notifications on server shutdown
- 🎯 Express Integration - Middleware for error handling, request logging, and health endpoints
- 📈 Metrics & Analytics - Historical metrics tracking and dashboard endpoints
📦 Installation
npm install pms_mdOptional Database Drivers
Install only the database drivers you need:
# SQL Databases
npm install pg # PostgreSQL
npm install mysql2 # MySQL
npm install mariadb # MariaDB
npm install mssql # MSSQL (SQL Server)
npm install sqlite3 # SQLite
# NoSQL Databases
npm install mongoose # MongoDB
npm install nano # CouchDB
npm install cassandra-driver # Cassandra
# Cache & Search
npm install ioredis # Redis
npm install @elastic/elasticsearch # Elasticsearch
# Cloud Databases
npm install @aws-sdk/client-dynamodb # DynamoDB
# Graph Databases
npm install neo4j-driver # Neo4j
# ORM
npm install sequelize # Sequelize (MySQL, PostgreSQL, SQLite, MSSQL)🚀 Quick Start
Basic Setup
const express = require('express');
const NodeMonitor = require('pms_md');
const app = express();
// Initialize monitor
const monitor = new NodeMonitor({
app: {
name: 'my-app',
environment: 'production'
},
notifications: {
email: {
enabled: true,
smtp: {
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_APP_PASSWORD
}
},
from: process.env.EMAIL_USER,
recipients: ['[email protected]']
}
}
});
// Add middleware
app.use(monitor.requestLogger());
app.use(monitor.errorMiddleware());
// Health endpoints
app.get('/health', monitor.healthCheckEndpoint());
app.get('/health/info', monitor.healthInfoEndpoint());
// Start monitoring
monitor.start();
// Start server
const server = app.listen(3000, () => {
console.log('Server running on port 3000');
});
// Graceful shutdown with email notifications
monitor.setupGracefulShutdown(server);
module.exports = app;🎨 Beautiful Monitoring UI (NEW!)
One-Line Integration 🚀
Add a complete monitoring dashboard to your app with just one line of code:
const express = require('express');
const NodeMonitor = require('pms_md');
const app = express();
const monitor = new NodeMonitor({
app: { name: 'My App' }
});
// ===== ONE LINE TO ENABLE ENTIRE UI! =====
monitor.serveUI(app);
monitor.start();
app.listen(3000);What You Get
After calling monitor.serveUI(app), you get:
- 🏠 Home Page -
/- Navigation hub with quick links - 📊 Dashboard -
/monitor/dashboard- Complete monitoring overview - 💚 Health Check -
/health- Live health status with auto-refresh - 📈 Metrics -
/monitor/metrics- Interactive charts (CPU, Memory) - 📋 Status -
/monitor/status- Real-time status overview - 🚨 Error Logs -
/monitor/error-logs- Error tracking
Features
✅ Zero Configuration - Works out of the box
✅ No File Copying - Everything served from node_modules
✅ Beautiful Design - Modern, responsive UI
✅ Real-time Updates - Auto-refresh dashboards
✅ Interactive Charts - Powered by Chart.js
✅ Dark/Light Theme - User preference support
✅ Content Negotiation - Supports both HTML and JSON
Advanced Configuration
// Custom base path
monitor.serveUI(app, {
basePath: '/monitoring',
appName: 'Production API',
enableErrorLogs: true
});
// UI now available at:
// http://localhost:3000/monitoring/
// http://localhost:3000/monitoring/dashboardScreenshots
Visit http://localhost:3000/ after starting your server to see the beautiful UI!
📚 Complete UI Integration Guide →
🗄️ Database Monitoring
MSSQL (SQL Server)
const sql = require('mssql');
const pool = await sql.connect({
server: 'localhost',
database: 'mydb',
user: 'sa',
password: 'password',
options: {
encrypt: true,
trustServerCertificate: true
}
});
monitor.registerDatabase('mssql', 'mssql', pool);PostgreSQL
const { Pool } = require('pg');
const pool = new Pool({
host: 'localhost',
database: 'mydb',
user: 'postgres',
password: 'password'
});
monitor.registerDatabase('postgres', 'postgresql', pool);MySQL / MariaDB
const mysql = require('mysql2/promise');
const pool = mysql.createPool({
host: 'localhost',
user: 'root',
password: 'password',
database: 'mydb'
});
monitor.registerDatabase('mysql', 'mysql2', pool);MongoDB
const mongoose = require('mongoose');
await mongoose.connect('mongodb://localhost:27017/mydb');
monitor.registerDatabase('mongodb', 'mongoose', mongoose.connection);Redis
const Redis = require('ioredis');
const redis = new Redis({
host: 'localhost',
port: 6379
});
monitor.registerDatabase('redis', 'redis', redis);SQLite
const sqlite3 = require('sqlite3');
const db = new sqlite3.Database('./mydb.sqlite');
monitor.registerDatabase('sqlite', 'sqlite', db);Cassandra
const cassandra = require('cassandra-driver');
const client = new cassandra.Client({
contactPoints: ['localhost'],
localDataCenter: 'datacenter1'
});
await client.connect();
monitor.registerDatabase('cassandra', 'cassandra', client);📊 Supported Databases
| Database | Type | Package | Status |
|----------|------|---------|--------|
| MongoDB | NoSQL | mongoose | ✅ |
| PostgreSQL | SQL | pg | ✅ |
| MySQL | SQL | mysql2 | ✅ |
| MariaDB | SQL | mariadb | ✅ |
| MSSQL | SQL | mssql | ✅ |
| SQLite | SQL | sqlite3 | ✅ |
| Redis | Cache | ioredis | ✅ |
| CouchDB | NoSQL | nano | ✅ |
| Cassandra | NoSQL | cassandra-driver | ✅ |
| Elasticsearch | Search | @elastic/elasticsearch | ✅ |
| DynamoDB | Cloud | @aws-sdk/client-dynamodb | ✅ |
| Neo4j | Graph | neo4j-driver | ✅ |
| Sequelize | ORM | sequelize | ✅ |
📧 Email Notifications
Gmail Setup
- Enable 2-Step Verification in your Google Account
- Generate App Password: https://myaccount.google.com/apppasswords
- Configure environment variables:
[email protected]
EMAIL_APP_PASSWORD=your-16-char-app-passwordConfiguration
const monitor = new NodeMonitor({
notifications: {
email: {
enabled: true,
smtp: {
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_APP_PASSWORD
}
},
from: process.env.EMAIL_USER,
recipients: ['[email protected]', '[email protected]']
}
}
});Notification Types
- ✅ Server Errors - Uncaught exceptions and unhandled rejections
- ✅ Database Failures - Connection loss and recovery
- ✅ Graceful Shutdown - Server shutdown notifications
- ✅ API Errors - HTTP 500 errors and critical failures
🎯 Express Middleware
Error Handling
// Automatic error tracking and email notifications
app.use(monitor.errorMiddleware());Request Logging
// Log all HTTP requests with sanitization
app.use(monitor.requestLogger());404 Handler
// Handle 404 errors
app.use(monitor.notFoundHandler());📈 Health Endpoints
Basic Health Check
app.get('/health', monitor.healthCheckEndpoint());Response:
{
"status": "healthy",
"timestamp": "2025-11-17T12:00:00.000Z",
"uptime": 3600,
"databases": {
"mssql": "connected",
"redis": "connected"
}
}Detailed Health Info
app.get('/health/info', monitor.healthInfoEndpoint());Response:
{
"status": "healthy",
"timestamp": "2025-11-17T12:00:00.000Z",
"uptime": 3600,
"system": {
"cpu": 45.2,
"memory": {
"used": 512,
"total": 8192,
"percentage": 6.25
}
},
"databases": {
"mssql": {
"status": "connected",
"type": "mssql",
"version": "Microsoft SQL Server 2019...",
"connections": 10
}
}
}🛡️ Graceful Shutdown
Automatically send email notifications when your server shuts down:
const server = app.listen(3000);
// Setup graceful shutdown with email notifications
monitor.setupGracefulShutdown(server);Features:
- ✅ Sends email notification on shutdown
- ✅ Closes all database connections
- ✅ Stops all monitoring intervals
- ✅ Handles SIGTERM and SIGINT signals
- ✅ Prevents memory leaks
📝 Advanced Configuration
Full Configuration Example
const monitor = new NodeMonitor({
app: {
name: 'my-production-app',
environment: 'production',
version: '1.0.0'
},
monitoring: {
enabled: true,
interval: 60000, // Check every 60 seconds
systemMetrics: true,
apiErrors: true
},
database: {
enabled: true,
checkInterval: 30000, // Check every 30 seconds
queryTimeout: 5000,
consecutiveFailuresThreshold: 3
},
notifications: {
email: {
enabled: true,
smtp: {
host: 'smtp.gmail.com',
port: 587,
secure: false,
auth: {
user: process.env.EMAIL_USER,
pass: process.env.EMAIL_APP_PASSWORD
}
},
from: process.env.EMAIL_USER,
recipients: ['[email protected]']
},
slack: {
enabled: false,
webhookUrl: process.env.SLACK_WEBHOOK_URL
}
},
logging: {
level: 'info',
directory: './logs',
maxFiles: '14d',
maxSize: '20m',
sanitize: true
}
});📚 API Reference
Core Methods
monitor.start()
Start all monitoring services.
monitor.stop()
Stop all monitoring services.
monitor.registerDatabase(name, type, connection)
Register a database for monitoring.
Parameters:
name(string) - Unique identifier for the databasetype(string) - Database type (e.g., 'mssql', 'postgresql', 'mongodb')connection(object) - Database connection object
monitor.getDatabaseStats(name)
Get statistics for a specific database.
Returns: Promise
monitor.getAllDatabaseStats()
Get statistics for all registered databases.
Returns: Promise
monitor.setupGracefulShutdown(server)
Setup graceful shutdown with email notifications.
Parameters:
server(object) - HTTP server instance
Middleware Methods
monitor.errorMiddleware()
Express middleware for error handling.
monitor.requestLogger()
Express middleware for request logging.
monitor.notFoundHandler()
Express middleware for 404 errors.
Endpoint Methods
monitor.healthCheckEndpoint()
Express endpoint handler for basic health check.
monitor.healthInfoEndpoint()
Express endpoint handler for detailed health information.
monitor.dashboardEndpoint()
Express endpoint handler for monitoring dashboard.
🧪 Testing
Run the comprehensive test suite:
node test-all-databases.jsTest Coverage:
- ✅ Package loading
- ✅ Monitor instantiation
- ✅ Database registration (all 13+ types)
- ✅ Health checks
- ✅ Statistics retrieval
- ✅ Peer dependencies
📖 Documentation
- Database Support Guide - Complete guide for all 13+ databases
- Quick Reference - Quick setup examples
- Changelog - Version history and updates
- Release Notes - Latest release information
🔧 Troubleshooting
Email Notifications Not Working
- Check Gmail App Password is correct (16 characters, no spaces)
- Verify 2-Step Verification is enabled
- Check environment variables are loaded
- Review logs in
./logsdirectory
Database Connection Failures
- Verify database driver is installed
- Check connection credentials
- Ensure database server is running
- Review database-specific logs
High Memory Usage
- Adjust
monitoring.intervalto reduce frequency - Reduce
logging.maxFilesretention period - Disable unused monitoring features
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
ISC License - see LICENSE file for details
👤 Author
Manish Proses
- Email: [email protected]
- GitLab: https://gitlab.com/manish-proses/pms_md
🙏 Acknowledgments
Built with:
- Winston - Logging
- Nodemailer - Email notifications
- Express - Web framework
📊 Version History
v1.0.3 (Latest)
- ✅ Added MSSQL (SQL Server) support
- ✅ Added MariaDB support
- ✅ Added SQLite support
- ✅ Added CouchDB support
- ✅ Added Cassandra support
- ✅ Added Elasticsearch support
- ✅ Added DynamoDB support
- ✅ Added Neo4j support
- ✅ Comprehensive documentation
- ✅ 100% test coverage
v1.0.2
- ✅ Enhanced MySQL2 support (v2 and v3)
- ✅ Added Sequelize ORM support
- ✅ Improved peer dependencies
v1.0.1
- ✅ Initial release
- ✅ MongoDB, PostgreSQL, MySQL, Redis support
- ✅ Email notifications
- ✅ Health monitoring
🚀 What's Next?
Planned features for future releases:
- TypeScript definitions
- Prometheus metrics export
- Custom alerting rules
- Performance profiling
- Distributed tracing
Made with ❤️ for the Node.js community
