Laravel App Monitor is a package designed to monitor specific HTTP errors in your Laravel application and notify administrators via email. It helps ensure that critical errors (like 500, 502, 503, 504, 413) are promptly reported, allowing administrators to take appropriate action.
You can install the Laravel App Monitor package via Composer. Run the following command in your terminal:
composer require tarique/laravel-app-monitorTo customize settings such as email recipients or error notifications, publish the configuration file:
php artisan vendor:publish --provider="Tarique\LaravelAppMonitor\AppMonitorServiceProvider" --tag=configThis will copy the configuration file to config/appmonitor.php and app\Jobs\SendMonitorErrorNotification.php.
Set the email address where notifications should be sent in your .env file:
ADMIN_EMAIL=admin@example.comMake sure to replace admin@example.com with the appropriate email address.
Laravel App Monitor automatically detects and handles specific HTTP errors. Here's how you can use it effectively:
Ensure that error notifications are enabled in the config/appmonitor.php file:
return [
'admin_email' => env('APPMONITOR_ADMIN_EMAIL', 'admin@example.com'),
'notify_on_down' => env('APPMONITOR_NOTIFY_ON_DOWN', true),
'notify_on_error' => env('APPMONITOR_NOTIFY_ON_ERROR', true),
'error_codes' => [500, 502, 503, 504, 413],
];If you want to customize the email template used for error notifications, you can publish the default template:
php artisan vendor:publish --provider="Tarique\LaravelAppMonitor\AppMonitorServiceProvider" --tag=viewsThis will copy the default email template to resources/views/vendor/appmonitor/error_email.blade.php, where you can modify it to suit your needs.
To avoid delaying frontend responses due to email sending, you can configure Laravel queues. Set the queue connection in your .env file:
QUEUE_CONNECTION=syncIf you are using QUEUE_CONNECTION as a database you should
QUEUE_CONNECTION=databaseRun the migration to create the jobs table:
php artisan queue:table
php artisan migrateStart the queue worker to process jobs asynchronously:
php artisan queue:workIf you encounter any issues or have questions about using Laravel App Monitor, please open an issue on GitHub or contact the package maintainer directly.
Laravel App Monitor is open-source software licensed under the MIT license.