Package Exports
- bodhi-node-profiler
Readme
Bodhi Node Profiler
🚀 A lightweight, zero-configuration performance profiler for Node.js applications with real-time dashboard
Quick Start • Features • Examples • Configuration • Support
🎯 Overview
Unlock the full potential of your Node.js applications with Bodhi Node Profiler! Monitor, debug, and optimize your application's performance in real-time with minimal setup. Whether you're debugging in development or monitoring in production, Bodhi Node Profiler provides the insights you need.
⚡️ Why Choose Bodhi Node Profiler?
- 🚀 One-Line Integration: Start profiling with minimal code changes
- 📊 Real-Time Dashboard: Beautiful, modern dashboard with live metrics
- 🔍 Comprehensive Metrics: CPU, Memory, Event Loop, and API performance
- ⚡ Production Ready: Low overhead (<50MB memory, <1% CPU)
- 🛠️ Developer Friendly: TypeScript & JavaScript support, Express.js integration
🆕 New Features!
- 📈 Enhanced Real-time Charts: Beautiful visualizations using Chart.js
- 🎯 Accurate CPU Monitoring: Improved CPU usage calculation
- ⏱️ API Response Time Tracking: Monitor endpoint performance
- 🔄 Event Loop Monitoring: Track event loop delays
- 💡 Smart Status Indicators: Visual health status for each metric
- ⌛ Uptime Tracking: Monitor your application's uptime
- 🎨 Modern UI: Clean, responsive dashboard design with Tailwind CSS
Quick Start
1. Install
npm install bodhi-node-profiler
2. Basic Usage
const express = require('express');
const { BodhiProfiler } = require('bodhi-node-profiler');
const app = express();
// Initialize profiler with modern dashboard
const profiler = new BodhiProfiler({
serviceName: 'my-app',
port: 45680, // Dashboard port
enableWebDashboard: true
});
app.use(profiler.middleware());
app.listen(3000, () => {
console.log('Server running on port 3000');
console.log('Profiler dashboard available at http://localhost:45680/profiler');
});
3. Access the Dashboard
Once your application is running, access the beautiful real-time dashboard at:
http://localhost:45680/profiler
Note: The dashboard port (45680) can be configured using the
port
option in the BodhiProfiler constructor.
Dashboard Features
The new dashboard provides:
📊 Real-time Metrics
- CPU Usage with status indicators (Good/Warning/High)
- Memory Usage and allocation tracking
- Event Loop Delay monitoring
- API Response Time analysis
📈 Live Charts
- CPU utilization trends
- Memory consumption patterns
- Event loop performance
- API response times
💻 System Information
- Total Memory usage
- Application Uptime
- Last Updated timestamp
🎨 Modern Design
- Clean, responsive layout
- Intuitive metric cards
- Status indicators
- Beautiful animations
Features
📊 Real-time Performance Monitoring
- CPU usage tracking
- Memory leak detection
- Event loop delay monitoring
- API response time analysis
- Custom metrics support
🔍 Comprehensive API Profiling
- Automatic endpoint detection
- Response time tracking
- Error rate monitoring
- Request/Response logging
- Route usage analytics
⚡ Production-Ready
- Minimal overhead
- Safe for production use
- Configurable logging
- Alert thresholds
- No external dependencies
🛠️ Developer Experience
- TypeScript support
- Express.js integration
- Beautiful web dashboard
- Easy configuration
- Detailed documentation
Usage Examples
1. REST API Server
const express = require('express');
const { BodhiProfiler } = require('bodhi-node-profiler');
const app = express();
// Custom configuration
const profiler = new BodhiProfiler({
logPath: './logs',
sampleInterval: 1000,
enableWebDashboard: true,
port: 8080
});
app.use(profiler.middleware());
// Your routes will be automatically profiled!
app.get('/api/users', async (req, res) => {
const users = await db.getUsers();
res.json(users);
});
2. GraphQL Server
const { ApolloServer } = require('apollo-server');
const { BodhiProfiler } = require('bodhi-node-profiler');
const profiler = new BodhiProfiler();
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [{
requestDidStart: () => ({
willSendResponse: (requestContext) => {
// Track GraphQL operation performance
profiler.trackOperation({
type: 'GraphQL',
name: requestContext.operationName,
duration: requestContext.request.duration
});
}
})
}]
});
3. Microservices Architecture
const express = require('express');
const { BodhiProfiler } = require('bodhi-node-profiler');
// Initialize with service-specific config
const profiler = new BodhiProfiler({
serviceName: 'auth-service',
logPath: './logs/auth-service',
tags: ['microservice', 'auth'],
alertThresholds: {
memory: 1024 * 1024 * 1024, // 1GB
cpu: 80, // 80% CPU usage
responseTime: 1000 // 1 second
}
});
// Get real-time metrics
app.get('/health', (req, res) => {
const metrics = profiler.getMetrics();
res.json({
status: 'healthy',
...metrics
});
});
4. Background Jobs
const { BodhiProfiler } = require('bodhi-node-profiler');
const profiler = new BodhiProfiler({
logPath: './logs/jobs'
});
async function processQueue() {
const start = Date.now();
try {
await heavyJob();
profiler.trackOperation({
type: 'Job',
name: 'processQueue',
duration: Date.now() - start
});
} catch (error) {
profiler.trackError({
type: 'Job',
name: 'processQueue',
error
});
}
}
Advanced Features
1. Custom Metrics
// Track custom business metrics
profiler.trackMetric({
name: 'activeUsers',
value: getUserCount(),
tags: ['business', 'users']
});
2. Performance Alerts
const profiler = new BodhiProfiler({
alerts: {
onHighMemory: (usage) => notifyDevOps('High memory usage detected', usage),
onHighCPU: (usage) => scaleService(),
onSlowEndpoint: (data) => logPerformanceIssue(data)
}
});
3. Memory Leak Detection
const profiler = new BodhiProfiler({
memoryLeakDetection: true,
heapSnapshotInterval: 3600000 // 1 hour
});
Log Management
The profiler now includes smart log management features:
Log Rotation
- Automatic log rotation based on size or date
- Compressed archives for space efficiency
- Configurable retention periods
logging: {
rotation: {
maxFiles: '7d', // Keep 7 days of logs
maxSize: '5m', // Rotate at 5MB
datePattern: 'YYYY-MM-DD',
compress: true // Compress old logs
}
}
Log Cleanup
- Automatic cleanup of old logs
- Configurable retention period
- Separate archive directory
logging: {
cleanup: {
enabled: true,
maxAge: '30d' // Delete logs older than 30 days
}
}
Metric Thresholds
Only log metrics when they exceed specified thresholds:
metrics: {
cpu: {
threshold: 70 // CPU usage > 70%
},
memory: {
threshold: 80 // Memory usage > 80%
},
eventLoop: {
threshold: 100 // Delay > 100ms
},
api: {
responseTime: {
threshold: 1000 // Response time > 1s
}
}
}
Configuration Options
Option | Type | Default | Description |
---|---|---|---|
logPath | string | './logs' | Directory for performance logs |
port | number | 8080 | Dashboard port |
sampleInterval | number | 1000 | Metrics collection interval (ms) |
enableWebDashboard | boolean | true | Enable/disable web dashboard |
serviceName | string | undefined | Service identifier for distributed systems |
tags | string[] | [] | Tags for metric categorization |
alertThresholds | object | {} | Performance alert thresholds |
Why Bodhi Node Profiler?
- Zero Configuration: Works out of the box with smart defaults
- Low Overhead: Minimal impact on application performance
- Real-time Insights: Instant visibility into performance issues
- No External Dependencies: Everything you need is included
- TypeScript Support: Full type definitions included
Performance Impact
- Memory Overhead: < 50MB
- CPU Overhead: < 1%
- Response Time Impact: < 0.5ms
Best Practices
Development:
- Enable all features for maximum insight
- Use lower sampling intervals for detailed data
Production:
- Adjust sampling intervals based on traffic
- Enable alerts for proactive monitoring
- Use log rotation for long-running services
💭 A Note from the Developer
Hey there! I'm Bodheesh VC, a passionate Node.js developer who believes in making development easier and more efficient for everyone. I created Bodhi Node Profiler because I felt the pain of debugging performance issues in production applications and wanted a simple, lightweight solution that just works.
This project is my contribution to the amazing Node.js community that has given me so much. It's built with love, attention to detail, and a focus on developer experience. Whether you're building a small API or a large microservices architecture, I hope this tool makes your development journey a little bit easier.
I'm actively maintaining this project and would love to hear your feedback! Feel free to reach out on Twitter or LinkedIn if you have questions or just want to chat about Node.js performance optimization.
Let's make the Node.js ecosystem better together! 🚀
Contributing
I believe in the power of community! If you'd like to contribute, here's how you can help:
- 🐛 Report bugs and issues on our GitHub Issues
- 💡 Suggest new features
- 📖 Improve documentation
- 🔧 Submit pull requests
- ⭐ Star the project if you find it useful!
Check out our Contributing Guide for more details.
Support
Need help? I'm here for you!
- 📧 Email: bodheeshvc.developer@gmail.com
- 🐦 Twitter: @bodheeshvc
- 💼 LinkedIn: bodheeshvc
- 💬 Discord: Join our community
License
MIT © Bodheesh VC