This Node.js script provides automated monitoring of applications managed by PM2, a production process manager for Node.js. It checks the status of each application, identifies those that are in a 'stopped' or 'nonExistent' state, and records these events in a log file (checking.log).
The script is designed to facilitate SMS notifications when applications encounter issues. It updates the checking.log file, adding a flag to indicate that an SMS notification should be sent. A key feature is the ability to control SMS notifications based on the time of day, allowing you to suppress notifications during off-hours (e.g., at night) if desired. This is managed through a configurable isNightModeActive setting.
The script is designed to run periodically (e.g., using cron or a similar task scheduler) to provide continuous monitoring and timely alerts.
npm install fs path moment
crontab -e
This will open the crontab file in a text editor. If this is the first time you're using crontab, it might ask you to choose an editor.
* * * * * /usr/bin/node /path/to/your/script.js >> /path/to/your/script.log 2>&1
▚ A Node.js script that monitors the status of PM2-managed applications, logs stopped or non-existent processes, and updates a log file to trigger SMS notifications based on configurable time-of-day rules.
Thank you for choosing the PM2 Checker! I hope it meets your needs effectively.
Please leave a comment if you have any comments, suggestions or problems.