What is Laravel Job Monitor?
Laravel Job Monitor is a lightweight package that records the lifecycle of queued jobs in your Laravel application. It stores timestamps, statuses, and execution details in a database table, allowing developers to query and visualize queue health without external services.
Why Monitor Queue Health?
- Identify bottlenecks: Spot jobs that run longer than expected.
- Detect failures early: Get visibility into failed jobs and the users they affect.
- Improve reliability: Use historical data to fine‑tune retry strategies and resource allocation.
- No extra infrastructure: Leverages your existing database, keeping the vendor footprint minimal.
How to Install Laravel Job Monitor
Installation requires only Composer and a single Artisan command.
- Run
composer require j-sandaruwan/laravel-job-monitorto add the package. - Publish the configuration and migration files:
php artisan vendor:publish --provider="JSandaruwan\LaravelJobMonitor\JobMonitorServiceProvider" - Run the migration to create the
job_monitortable:php artisan migrate
How to Configure the Package
After publishing, edit config/job-monitor.php to adjust retention periods, notification channels, or custom table names. The default settings work for most projects.
How to Use Laravel Job Monitor
Once installed, the package automatically hooks into Laravel's queue events.
- Recording: Each job dispatch creates a record with
queued_at,started_at,finished_at, andstatusfields. - Querying: Use the provided
JobMonitormodel to retrieve statistics, e.g.,JobMonitor::whereStatus('failed')->lastWeek()->get(); - API endpoint: The package exposes
GET /api/job-monitor/jobs/statsto fetch aggregated health metrics such as total jobs, failures, and average processing time.
Key Features
- Zero external dependencies – uses only your existing database.
- Automatic event listeners for all Laravel queue drivers.
- Aggregated statistics endpoint for dashboard integration.
- Extensible configuration for custom notifications (Slack, Discord, etc.).
Best Practices
- Retain job records for a reasonable period (e.g., 30 days) to balance insight and storage.
- Combine the API stats with a simple Blade dashboard for real‑time monitoring.
- Set up alerting on the
failedstatus to react quickly to critical issues.