A powerful and flexible system monitoring library for Node.js applications with built-in support for multiple notification providers.
- π System Metrics Monitoring
- CPU usage and load
- Memory utilization
- Disk space
- Process information
- π¨ Multiple Notification Providers
- Discord webhooks
- Telegram bots
- Email notifications
- βοΈ Advanced Configuration
- Customizable monitoring intervals
- Flexible threshold settings
- Duration-based alerts
- Custom metrics support
- π‘οΈ Reliability
- Error handling
- Retry mechanisms
- Graceful failure handling
# Using npm
npm install watchdock
# Using yarn
yarn add watchdock
# Using pnpm
pnpm add watchdockimport { SystemMonitor } from 'watchdock';
const monitor = new SystemMonitor({
interval: '*/5 * * * *', // Check every 5 minutes
application: {
name: 'HAMORA API',
metadata: {
version: '1.0.0',
},
},
providers: [
{
type: 'discord',
webhookUrl: 'your-discord-webhook-url',
},
{
type: 'telegram',
botToken: 'your-telegram-bot-token',
chatId: 'your-chat-id',
},
],
notifications: {
cpu: {
value: 80, // Notify when CPU > 80%
duration: 5, // Must exceed for 5 minutes
notify: true,
},
memory: {
value: 90, // Notify when memory > 90%
notify: true,
},
disk: {
value: 95, // Notify when disk > 95%
notify: true,
},
status: {
notifyOn: ['unhealthy', 'degraded'], // Notify on these states
},
},
});
monitor.start();interface MonitorConfig {
// Cron expression for monitoring interval
interval: string;
// Array of notification providers
providers: NotificationConfig[];
// Optional environment name
env?: string;
// Optional custom metrics collector
customMetrics?: () => Promise<ApplicationMetrics>;
// Notification rules
notifications?: NotificationRules;
}{
type: "discord",
webhookUrl: "your-webhook-url",
username?: "Custom Bot Name",
avatarUrl?: "https://your-avatar-url.com/image.png"
}{
type: "telegram",
botToken: "your-bot-token",
chatId: "your-chat-id"
}{
type: "email",
host: "smtp.example.com",
port: 587,
secure: true,
auth: {
user: "your-email@example.com",
pass: "your-password"
},
from: "monitor@example.com",
to: ["admin@example.com"]
}You can add your own application metrics:
const monitor = new SystemMonitor({
// ... other config
customMetrics: async () => ({
activeConnections: await getActiveConnections(),
requestCount: await getRequestCount(),
errorRate: await calculateErrorRate(),
responseTime: await getAverageResponseTime(),
}),
});The monitoring system collects and reports the following metrics:
interface MetricsReport {
timestamp: string;
status: 'healthy' | 'degraded' | 'unhealthy';
errors: string[];
system: {
cpu: {
usage: number;
count: number;
loadAvg: number[];
};
memory: {
total: number;
free: number;
used: number;
heapTotal: number;
heapUsed: number;
external: number;
rss: number;
};
disk: {
total: number;
free: number;
used: number;
usedPercentage: number;
};
process: {
uptime: number;
pid: number;
version: string;
};
};
application: ApplicationMetrics;
}notifications: {
cpu: {
value: 80,
duration: 5, // Only alert if CPU > 80% for 5+ minutes
notify: true
}
}Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Rafael Batista Santos
- Github: @raphab3
- LinkedIn: @rafael-batista-santos
Give a βοΈ if this project helped you!
Built with β€οΈ by Rafael Batista Santos

