process-guard
v1.0.0
Published
Ultra-lightweight process manager with auto-restart, real-time monitoring, multi-channel notifications, live dashboard, and cloud sync — the PM2 alternative that just works.
Downloads
156
Maintainers
Readme
🛡️ process-guard
Ultra-lightweight process manager with auto-restart, real-time monitoring,
multi-channel notifications, live dashboard, and optional cloud sync.
"One command. Your server never sleeps again."
Why process-guard?
Your server crashed at 4 AM. You slept. Your users didn't.
PM2 is powerful — but overkill for most projects and hard to learn.
process-guard gives you what you actually need in one command:
npx process-guard node server.js --restart --notify telegram --token BOT_TOKEN --chat-id CHAT_ID✅ Auto-restart on crash
✅ Memory & CPU monitoring
✅ Telegram / Slack / Discord / Email alerts
✅ Beautiful live dashboard
✅ Zero config needed
Installation
npm install -g process-guard # global CLI
npm install process-guard # project dependencyQuick Start
# Auto-restart only
npx process-guard node server.js --restart
# + Telegram alerts
npx process-guard node app.js \
--restart \
--notify telegram \
--token YOUR_BOT_TOKEN \
--chat-id YOUR_CHAT_ID
# + Live dashboard
npx process-guard node app.js \
--restart --dashboard --dashboard-port 9000
# Full setup
npx process-guard node server.js \
--restart \
--notify slack --token WEBHOOK_URL \
--dashboard --dashboard-port 9000 \
--max-memory 512 --max-cpu 85CLI Options
Usage: process-guard <command> [options]
Options:
-r, --restart Enable automatic restart on crash
--strategy <name> exponential | fixed | linear | immediate (default: exponential)
--restart-delay <ms> Base restart delay (default: 1000)
--max-restarts <n> Max restart attempts per hour (default: 10)
--max-memory <mb> Memory threshold in MB (default: 512)
--max-cpu <pct> CPU threshold in % (default: 90)
--check-interval <ms> Polling interval (default: 5000)
-n, --notify <channel> telegram | slack | discord | email
-t, --token <value> Bot token or Webhook URL
--chat-id <id> Telegram chat ID
--notify-level <level> Minimum notification level (default: warning)
-d, --dashboard Enable live web dashboard
-p, --dashboard-port <port> Dashboard port (default: 9000)
--dashboard-password <pass> Protect dashboard with a password
--cloud-key <key> process-guard cloud API key
--log-level <level> debug | info | warning | error (default: info)
--log-json Output JSON logs
--no-color Disable colour output
-v, --version Print version
-h, --help Show this helpProgrammatic API
const ProcessGuard = require('process-guard');
const guard = new ProcessGuard('node server.js', {
restart: {
enabled : true,
strategy : 'exponential',
maxRestarts: 10,
},
monitor: {
memoryThreshold: 512, // MB
cpuThreshold : 85, // %
},
notifications: {
enabled : true,
minLevel: 'warning',
telegram: {
botToken: process.env.TELEGRAM_TOKEN,
chatId : process.env.TELEGRAM_CHAT_ID,
},
},
dashboard: { enabled: true, port: 9000 },
});
guard.on('crash', (e) => console.log('Crash!', e));
guard.on('memory-warning', ({ value }) => console.log(`Memory: ${value}MB`));
guard.on('max-restarts-exceeded', () => process.exit(4));
await guard.start();Live Dashboard
Open http://localhost:9000 after enabling --dashboard.
Features:
- Real-time memory & CPU charts (WebSocket-powered)
- Process status, PID, uptime, restart count
- Error / warning event log
- Memory leak detector
- One-click restart & stop
Notification Channels
| Channel | Setup | |---------|-------| | Telegram | Create a bot with @BotFather, copy token + chat_id | | Slack | Create an Incoming Webhook in your workspace | | Discord | Server → Integrations → Webhooks → Create | | Email | Any SMTP server (Gmail, SendGrid, Mailgun, …) |
Project Structure
process-guard/
├── bin/process-guard.js # CLI entry point
├── src/
│ ├── index.js # Main ProcessGuard class
│ ├── core/
│ │ ├── ProcessManager.js # Spawn, I/O, lifecycle
│ │ ├── Monitor.js # CPU & memory polling
│ │ ├── Restart.js # Smart restart policies
│ │ └── Detector.js # Pattern-based crash detection
│ ├── notifiers/
│ │ ├── NotifierBase.js # Base class (retry, rate-limit)
│ │ ├── TelegramNotifier.js
│ │ ├── SlackNotifier.js
│ │ ├── DiscordNotifier.js
│ │ └── EmailNotifier.js
│ ├── metrics/
│ │ ├── MetricsCollector.js # Orchestrator
│ │ ├── MemoryTracker.js # Leak detection
│ │ ├── CPUTracker.js # Spike detection + P95
│ │ └── StorageManager.js # NDJSON persistence
│ ├── dashboard/
│ │ ├── DashboardServer.js # Express + WebSocket server
│ │ ├── api/routes.js # REST endpoints
│ │ ├── api/middleware.js # Auth + CORS
│ │ └── assets/ # HTML / CSS / JS (no build step)
│ ├── cloud/
│ │ ├── CloudClient.js # HTTP client
│ │ ├── Auth.js # JWT auth
│ │ └── Sync.js # Background sync loop
│ ├── config/
│ │ ├── DefaultConfig.js
│ │ ├── ConfigParser.js # File + env-var resolution
│ │ └── validators.js
│ └── utils/
│ ├── Logger.js # Levelled, coloured logger
│ ├── helpers.js
│ └── constants.js
├── examples/ # Runnable examples
├── tests/ # Jest unit + integration tests
└── docs/ # Full documentationDocumentation
| Guide | Description | |-------|-------------| | Getting Started | Installation & quick start | | Configuration | All options explained | | Notifiers | Set up Telegram, Slack, Discord, Email | | Dashboard | Live web dashboard guide | | API Reference | Programmatic API & events | | Cloud Service | Remote monitoring ($8/mo) | | Troubleshooting | Common issues & fixes |
License
MIT — free for personal and commercial use.
