Production-ready queue monitoring and metrics collection for Laravel applications.
Laravel Queue Metrics provides deep observability into your Laravel queue system with minimal overhead. Track job execution, monitor worker performance, analyze trends, and export to Prometheus—all with zero configuration required.
- 🚀 Zero Configuration - Works out-of-the-box
- ⚡ Minimal Overhead - ~1-2ms per job
- 📊 Rich Insights - Duration, memory, CPU, throughput, trends
- 🎯 Production Ready - Battle-tested at scale
- 🔌 Extensible - Events for customization and reactive monitoring
- 📈 Prometheus Ready - Native metrics export
- 🏗️ DX First - Clean facade API and comprehensive docs
use PHPeek\LaravelQueueMetrics\Facades\QueueMetrics;
// Get job performance metrics
$metrics = QueueMetrics::getJobMetrics(ProcessOrder::class);
echo "Processed: {$metrics->totalProcessed}\n";
echo "P95 Duration: {$metrics->duration->p95}ms\n";
echo "Failure Rate: {$metrics->failureRate}%\n";
echo "Health Score: {$metrics->health->score}/100\n";
// React to events
Event::listen(HealthScoreChanged::class, function ($event) {
if ($event->toStatus === 'critical') {
Slack::alert("Queue health critical!");
}
});- Installation - Get up and running
- Quick Start - 5-minute walkthrough
- Configuration - Customize behavior
- Facade API - Developer interface
- HTTP API - REST endpoints
- Prometheus - Monitoring integration
- Events - React to metrics changes
- Architecture - How it works
- Multi-Tenancy - SaaS integration patterns
- Auto-Scaling - Cloud provider integration
- Alert Systems - Monitoring and alerts
- Custom Dashboards - Build UIs
composer require gophpeek/laravel-queue-metricsThat's it! The package auto-registers and starts collecting metrics immediately.
For database storage, run migrations:
php artisan vendor:publish --tag="laravel-queue-metrics-migrations"
php artisan migrateTrack execution time, memory usage, CPU time, throughput, and failure rates per job class with percentile statistics (P50, P95, P99).
Monitor queue depth, processing rates, failure rates, and health scores with automatic issue detection.
Real-time worker status, resource consumption, efficiency metrics, and stale worker detection.
Historical analysis with linear regression, forecasting, and anomaly detection for proactive insights.
Automatic baseline calculation to detect performance degradation and regressions.
Redis (fast, in-memory) or Database (persistent) backends with automatic TTL cleanup.
Native Prometheus metrics endpoint for Grafana dashboards and alerting.
Complete HTTP API for integration with custom dashboards and monitoring tools.
Extensible architecture with events for reactive monitoring and notifications.
- PHP 8.3+
- Laravel 11.0+ or 12.0+
- Redis or Database for metrics storage
Note: Laravel 12.19+ is recommended for most accurate queue metrics (Laravel PR #56010). Earlier versions use driver-specific implementations.
Redis (Recommended for Production):
QUEUE_METRICS_STORAGE=redis
QUEUE_METRICS_CONNECTION=defaultDatabase (For Persistence):
QUEUE_METRICS_STORAGE=database// config/queue-metrics.php
'api' => [
'enabled' => true,
'middleware' => ['api', 'auth:sanctum'], // Secure the API
],// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('queue-metrics:trends:record')->everyFiveMinutes();
$schedule->command('queue-metrics:workers:detect-stale')->everyMinute();
$schedule->command('queue-metrics:baseline:calculate')->daily();
}→ Complete configuration reference
$metrics = QueueMetrics::getJobMetrics(ProcessOrder::class);
if ($metrics->duration->p95 > 5000) {
alert("ProcessOrder is slow: {$metrics->duration->p95}ms");
}
if ($metrics->failureRate > 5) {
alert("ProcessOrder failing: {$metrics->failureRate}%");
}$queue = QueueMetrics::getQueueMetrics('redis', 'default');
if ($queue->health->status === 'critical') {
PagerDuty::alert("Queue critical: {$queue->health->score}/100");
}
if ($queue->depth->total > 10000) {
Log::warning("Queue depth high: {$queue->depth->total}");
}Event::listen(WorkerEfficiencyChanged::class, function ($event) {
if ($event->getScalingRecommendation() === 'scale_up') {
AutoScaler::scaleUp($event->activeWorkers + 2);
}
});use PHPeek\LaravelQueueMetrics\Events\MetricsRecorded;
Event::listen(MetricsRecorded::class, function (MetricsRecorded $event) {
// Log with tenant context
Log::info('Job metrics recorded', [
'tenant_id' => tenant('id'),
'tenant_plan' => tenant('plan'),
'job' => $event->metrics->jobClass,
'duration' => $event->metrics->duration->avg,
]);
});# System overview
GET /queue-metrics/overview
# Job metrics
GET /queue-metrics/jobs/App\\Jobs\\ProcessOrder
# Queue health
GET /queue-metrics/queues/default?connection=redis
# Active workers
GET /queue-metrics/workers
# Prometheus export
GET /queue-metrics/prometheus# prometheus.yml
scrape_configs:
- job_name: 'laravel-queues'
static_configs:
- targets: ['your-app.test']
metrics_path: '/queue-metrics/prometheus'
scrape_interval: 30sQuery metrics:
# Queue depth
queue_depth{connection="redis",queue="default"}
# Job duration P95
job_duration_p95_ms{job_class="App\\Jobs\\ProcessOrder"}
# Failure rate
job_failure_rate > 5
Laravel Queue Metrics uses a clean, layered architecture:
- Event Listeners → Capture Laravel queue events
- Actions → Business logic for recording metrics
- Repositories → Data access abstraction
- Storage Drivers → Pluggable backends (Redis/Database)
- Services → High-level business operations
- DTOs → Type-safe, immutable data structures
- Events → Reactive monitoring and notifications
- Per-job overhead: ~1-2ms (Redis), ~5-15ms (Database)
- Memory overhead: ~5-10MB package classes, ~1-2KB per job record
- Tested throughput: 10,000+ jobs/minute
- Storage: Auto-cleanup via TTL (Redis) or manual cleanup (Database)
composer test
composer analyse
composer formatPlease see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.