If you ever lost data, money or customers because of a failing cron job that went unnoticed, you’ll know how important it is to monitor cron jobs.
There are a lot of different ways to monitor a cron job. Here are a couple of examples:
- Instructing cron to always send all output and errors via email: https://stackoverflow.com/questions/19451680/how-to-save-cronjob-error-to-file-and-email-it
- Instructing cron to only send an email when an error happens: https://stackoverflow.com/questions/19451680/how-to-save-cronjob-error-to-file-and-email-it
Solution #1 above is very noisy and will bombard your email address with lots of emails especially if you have a lot of cron jobs and they frequently run. The good thing about it is you’ll know if your cron jobs actually ran or an error happened. But this is only useful if you always and immediately check the sent emails.
Solution #2 above is better but it won’t notify you on some scenarios like cron is not running at all or if the server is down for some reason.
Another downside by using the solutions above is you’ll need to make sure that your server is able to send emails and make sure the emails doesn’t get marked as spam:
Plus other things that you need to worry about that I probably failed to mention here. These are all good if you love to DIY but if you want a more convenient way to monitor cron jobs, an alternative and better way is to use a cron job monitoring tool like CronMonit.
Setting up a cron job to be monitored via CronMonit only takes less than 5 minutes. You just have to create a check using CronMonit’s dashboard and configure your cron job to ping the check once it is done running by sending an HTTP request to the given ping URL.
If your cron job is:
* * * * * script.sh
..it will become:
* * * * * script.sh && curl -fsS --retry 3 https://cronmonit.app/ping-check/91b5a171-6721-4657-b05e-35f5dde5dc0f > /dev/null
Once your cron job pings the check for the first time, CronMonit will start monitoring your cron job. If ever your cron job fails (e.g, an error happens or the cron job doesn’t run at all), you’ll get notified via email.
And by using CronMonit, if cron is not running at all or if the server is down, you’ll still get notified that there’s a problem with your cron job!
You’ll also get a simple dashboard for viewing monitored cron jobs where you can easily see which jobs are up or down:
It is really useful especially if you have a lot of cron jobs. You’ll also be able to view logs of pings and status changes which provides some useful insights about your cron jobs:
Checks can be organized by projects too:
We're currently using it on a project that uses lots of cron jobs.
Signup and start monitoring your cron jobs for free: https://cronmonit.app
Top comments (0)