Skip to content

Commit 84d9892

Browse files
Document queue exporters
1 parent a848a7b commit 84d9892

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

docs/basic-usage/_index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22
title: Basic usage
33
weight: 1
44
---
5+
6+
This section covers basic usage of the Laravel Prometheus package, including:
7+
8+
- [Creating gauges]({{< ref "creating-gauges" >}}) - Learn how to create and register custom gauge metrics
9+
- [Using Horizon exporters]({{< ref "using-horizon-exporters" >}}) - Export Laravel Horizon metrics to Prometheus
10+
- [Using Queue exporters]({{< ref "using-queue-exporters" >}}) - Export Laravel queue metrics to Prometheus
11+
- [Using cached values]({{< ref "using-cached-values" >}}) - Optimize performance with cached metric values
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
```

docs/introduction.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,23 @@ Prometheus::addGauge('User count')
1313
These metrics will be exposed at the `/prometheus` endpoint. The package offers a way to add a security layer, so your key metrics don't become public.
1414

1515
You can configure your Prometheus instance to periodically crawl and import the metrics at the `/prometheus` endpoint of your app. Using [Grafana](https://grafana.com), you can visualize the data points that are stored in Prometheus.
16+
17+
## Built-in Collectors
18+
19+
The package includes several built-in collectors for common Laravel functionality:
20+
21+
### Queue Metrics
22+
Monitor your Laravel queues with comprehensive metrics including queue sizes, pending jobs, delayed jobs, and more. Supports all Laravel queue drivers (Redis, Database, SQS, etc.) with graceful fallbacks. If you're using Horizon, please use the Horizon collectors listed below instead!
23+
24+
```php
25+
// Enable all queue collectors
26+
$this->registerQueueCollectors(['high', 'normal', 'low'], 'redis');
27+
```
28+
29+
### Horizon Metrics
30+
Export Laravel Horizon metrics including supervisor status, workload distribution, job throughput, and failure rates.
31+
32+
```php
33+
// Enable all Horizon collectors
34+
$this->registerHorizonCollectors();
35+
```

0 commit comments

Comments
 (0)