arrow_back Back to Tickets

Ticket #e24045

open

Problem

pm2 script that notifies me via email of a condition in the logs.

Creator

marcus

Priority

5

Important

not_important

Project Name

zfrika

Notes

Since we’re focusing strictly on PM2, you have two primary paths: using the official (but paid) monitoring dashboard or setting up a free, lightweight "log watcher" on your server. Here are the best ways to get notifications directly from PM2. 1. PM2 Plus (The Easiest Method) PM2 Plus is a web-based management system. It is the only "native" way to get real-time push/email notifications without writing custom code. How to set it up: Run pm2 plus in your terminal to link your server to the dashboard. Alerting: In the "Events" or "Issues" tab, you can configure Triggers. Conditions: You can set alerts for process crashes, high memory usage, or specific error strings appearing in the logs. 2. PM2 API (The Programmatic Method) If you want to keep it free and custom, you can write a tiny "Watchdog" script in Node.js using the pm2 npm package. This script stays separate from your app and listens to PM2 events. JavaScript const pm2 = require('pm2'); pm2.connect((err) => { if (err) { console.error(err); process.exit(2); } // "bus" allows you to listen to all PM2 log events pm2.launchBus((err, bus) => { bus.on('log:err', (data) => { if (data.data.includes('YOUR_TARGET_CONDITION')) { sendNotification(data.data); } }); }); }); function sendNotification(message) { // Logic for Slack Webhook, Twilio SMS, or Email console.log("Notification Sent: " + message); } 3. Using pm2-logrotate + Log Watching If your main concern is the logs growing too large or searching through them, you should install the log rotate module. Then, use a standard Linux utility like Swatchdog (Simple Watchdog) to monitor the resulting files. Summary of Options Feature PM2 Plus PM2 API (Custom Script) Fail2Ban / Swatch Effort Low (UI based) Medium (Coding required) Medium (Config based) Cost Free tier available / Paid Free Free Reliability Very High High (if script is managed) High Would you like me to help you write a script for a specific notification service, like Slack, Discord, or Email?

Ticket Information

Ticket ID: 695c8bc9df2473a6c8e24045
Date Initiated: 1/5/2026, 8:12:00 PM
Status: open
Important: not_important
Created: 1/5/2026, 8:12:57 PM
Last Updated: 1/5/2026, 8:12:57 PM