Appearance
Monitoring with Oh Dear
Health checks
See https://ohdear.app/docs/features/application-health-monitoring#laravel
Monitoring scheduled tasks (cron jobs)
Oh Dear can be configured to monitor scheduled tasks, giving alerts when a task fails to start or complete.
For Laravel projects, the spatie/laravel-schedule-monitor package can be used to automatically configure Oh Dear monitors for schedule tasks.
Follow the installation instructions at https://github.com/spatie/laravel-schedule-monitor, bearing in mind the following points:
It is usually unnecessary to publish or amend the config file.
The
schedule-monitor:synccommand should be added to the Forge deploy script, or the Composer deploy script if applicable:shell$FORGE_PHP artisan schedule-monitor:syncjson"scripts": { "deploy": [ "...", "@php artisan schedule-monitor:sync" ] }A maximum of 5 scheduled tasks should be monitored per project to ensure we remain within our Oh Dear subscription limits. Use the
->doNotMonitorAtOhDear()helper to disable monitoring on Oh Dear for less important tasks. This will maintain the monitoring locally, just avoid pushing it to Oh Dear.For any tasks that typically take longer than 5 minutes, set a suitable grace period via the
->graceTimeInMinutes()helper.Tasks with a large number of arguments and options can cause false positives, especially if any of these are dynamic. Consider setting a monitor name via the
->monitorName()helper for any applicable tasks.
Syncing with Oh Dear
To sync with Oh Dear, credentials need to be provided:
- Create a new API token with access to the relevant site.
- Enable the 'Scheduled tasks' monitor in Oh Dear, and obtain the
Monitor IDfrom the 'Settings' tab.
These should be configured as environment variables:
dotenv
OH_DEAR_API_TOKEN=randomstring
OH_DEAR_MONITOR_ID=12345
OH_DEAR_SEND_STARTING_PING=trueSetting OH_DEAR_SEND_STARTING_PING=true will allow Oh Dear to show start times for each instance of a scheduled task, as well as finish times.