├── README.md
├── composer.json
├── resources
└── views
│ ├── date.blade.php
│ ├── status-json.php
│ ├── status-page.blade.php
│ ├── status-panel.blade.php
│ └── status.blade.php
└── src
├── Command
└── QueueQueueCheckCommand.php
├── Job.php
├── QueueChecker.php
├── QueueMonitor.php
├── QueueStatus.php
└── ServiceProvider.php
/README.md:
--------------------------------------------------------------------------------
1 | Laravel queue monitor
2 | =====================
3 |
4 | This adds various tools to a project for monitoring its queue.
5 |
6 | Laravel version
7 | ---------------
8 |
9 | This branch and the `2.*` line of tags are for Laravel 5. For the Laravel 4
10 | version [see the laravel4 branch][l4] and the `1.*` line of tags.
11 |
12 | If you are using Laravel 5.5 or later, and are using PHP 7.1 or later,
13 | and your queue is backed by Redis,
14 | you may instead consider using [Laravel Horizon][horizon],
15 | which is an official tool and solves the same issue as this package.
16 |
17 | [l4]: https://github.com/tremby/laravel-queue-monitor/tree/laravel4
18 | [horizon]: https://laravel.com/docs/5.5/horizon
19 |
20 | Installation
21 | ------------
22 |
23 | Require it in your Laravel project:
24 |
25 | composer require tremby/laravel-queue-monitor
26 |
27 | If you're running Laravel 5.4 or below,
28 | you have to register the service provider manually
29 | in your `config/app.php` file:
30 |
31 | ```php
32 | 'providers' => [
33 | ...
34 | Tremby\QueueMonitor\ServiceProvider::class,
35 | ],
36 | ```
37 |
38 | Use
39 | ---
40 |
41 | Add a cron job which runs the `queue:queuecheck` Artisan task for each queue you
42 | want to monitor. A queue name can be passed as an argument, or the default queue
43 | name is used if none is given. See `./artisan queue:queuecheck --help` for full
44 | details.
45 |
46 | Example cron job to check the default queue every 15 minutes:
47 |
48 | */15 * * * * php /home/forge/example.com/artisan queue:queuecheck
49 |
50 | This task records in the application cache (for one day) that a check for this
51 | queue is pending, then pushes a job to this queue. This job changes that cached
52 | status to "OK", so if the job doesn't run for whatever reason the status will be
53 | left at "pending".
54 |
55 | The status of all queue monitors can be checked by rendering one of the provided
56 | status views. The markup of the provided views are [Twitter
57 | Bootstrap](http://getbootstrap.com/)-friendly and if the `status-page` view is
58 | used Bootstrap is loaded from a CDN.
59 |
60 | ```php
61 | Route::get('queue-monitor', function () {
62 | return Response::view('queue-monitor::status-page');
63 | });
64 | ```
65 |
66 | Other views available are `queue-monitor::status-panel`, which is the `.panel`
67 | element and its contents; and `queue-monitor::status`, which is just the `table`
68 | element. Either of these could be used to plug this monitor into a larger
69 | monitoring panel. A `panel_class` option can be passed, which defaults to
70 | `panel-default`.
71 |
72 | There's also `queue-monitor::status-json`, which renders JSON suitable for
73 | machine consumption. This allows rendering options to be passed to the
74 | underlying `json_encode` and can be used like this:
75 |
76 | ```php
77 | Route::get('queue-monitor.json', function () {
78 | $response = Response::view('queue-monitor::status-json', [
79 | 'options' => \JSON_PRETTY_PRINT,
80 | ]);
81 | $response->header('Content-Type', 'application/json');
82 | return $response;
83 | });
84 | ```
85 |
86 | In practice you might set the cron job to run every 15 minutes, and then
87 | automate another job (such as with a remote health checker) to run a few minutes
88 | later, consume the JSON, and ensure all queues have the `ok` status. If any
89 | don't, it could send an alert with a link to the HTML queue status view. It
90 | could also check that the date at which the last check was queued is reasonable,
91 | and so that the cron job has not stopped working.
92 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "tremby/laravel-queue-monitor",
3 | "description": "Laravel queue monitoring tools",
4 | "require": {
5 | "php": ">=5.6.4",
6 | "laravel/framework": "~5.1"
7 | },
8 | "license": "MIT",
9 | "authors": [
10 | {
11 | "name": "Bart Nagel",
12 | "email": "bart@tremby.net"
13 | }
14 | ],
15 | "autoload": {
16 | "psr-4": {
17 | "Tremby\\QueueMonitor\\": "src/"
18 | }
19 | },
20 | "extra": {
21 | "laravel": {
22 | "providers": [
23 | "Tremby\\QueueMonitor\\ServiceProvider"
24 | ]
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/resources/views/date.blade.php:
--------------------------------------------------------------------------------
1 | @if ($date)
2 |
5 | @else
6 |
7 | null
8 |
9 | @endif
10 |
--------------------------------------------------------------------------------
/resources/views/status-json.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |