|
| 1 | +--- |
| 2 | +title: Using Queue exporters |
| 3 | +weight: 3 |
| 4 | +--- |
| 5 | + |
| 6 | +> **Important**: If you are using Laravel Horizon, you should use the [Horizon exporters](./using-horizon-exporters.md) instead of these queue exporters. Horizon provides its own comprehensive queue monitoring and these two exporters should not be used together as they may conflict or provide duplicate metrics. |
| 7 | +
|
| 8 | +We can export key metrics from Laravel's built-in queue system to Prometheus. To enable this feature, uncomment this line in the `app/Providers/PrometheusServiceProvider.php` file. |
| 9 | + |
| 10 | +```php |
| 11 | +$this->registerQueueCollectors(['default']); |
| 12 | +``` |
| 13 | + |
| 14 | +This will register the following collectors for monitoring your Laravel queues: |
| 15 | + |
| 16 | +- `queue_size`: exports the total number of jobs in each queue |
| 17 | +- `queue_pending_jobs`: exports the number of pending jobs per queue |
| 18 | +- `queue_delayed_jobs`: exports the number of delayed jobs per queue (supported drivers) |
| 19 | +- `queue_reserved_jobs`: exports the number of reserved jobs per queue |
| 20 | +- `queue_oldest_pending_job_age`: exports the age of the oldest pending job in seconds (supported drivers) |
| 21 | + |
| 22 | +## Configuration |
| 23 | + |
| 24 | +### Basic Usage |
| 25 | + |
| 26 | +Register collectors for the default connection and default queue: |
| 27 | + |
| 28 | +```php |
| 29 | +$this->registerQueueCollectors(['default']); |
| 30 | +``` |
| 31 | + |
| 32 | +### Custom Connection |
| 33 | + |
| 34 | +Monitor queues on a specific connection: |
| 35 | + |
| 36 | +```php |
| 37 | +$this->registerQueueCollectors(['high', 'low'], 'redis'); |
| 38 | +``` |
| 39 | + |
| 40 | +## Prometheus Metrics |
| 41 | + |
| 42 | +All metrics include `connection` and `queue` labels for filtering and aggregation: |
| 43 | + |
| 44 | +``` |
| 45 | +# HELP app_queue_size The total number of jobs in the queue |
| 46 | +# TYPE app_queue_size gauge |
| 47 | +app_queue_size{connection="redis",queue="high"} 45 |
| 48 | +app_queue_size{connection="redis",queue="low"} 12 |
| 49 | +
|
| 50 | +# HELP app_queue_delayed_jobs The number of delayed jobs in the queue |
| 51 | +# TYPE app_queue_delayed_jobs gauge |
| 52 | +app_queue_delayed_jobs{connection="redis",queue="high"} 3 |
| 53 | +app_queue_delayed_jobs{connection="redis",queue="low"} 0 |
| 54 | +``` |
| 55 | + |
| 56 | +## Individual Collectors |
| 57 | + |
| 58 | +You can also register collectors individually with custom parameters in your `PrometheusServiceProvider`. |
| 59 | + |
| 60 | +```php |
| 61 | +use Spatie\Prometheus\Collectors\Queue\QueueSizeCollector; |
| 62 | +use Spatie\Prometheus\Collectors\Queue\QueueDelayedJobsCollector; |
| 63 | + |
| 64 | +Prometheus::registerCollectorClasses([ |
| 65 | + QueueSizeCollector::class, |
| 66 | + QueueDelayedJobsCollector::class, |
| 67 | +], ['connection' => 'redis', 'queues' => ['critical', 'high', 'normal']]); |
| 68 | +``` |
0 commit comments