mattyeend/queue-monitor
最新稳定版本:v1.1.12
Composer 安装命令:
composer require mattyeend/queue-monitor
包简介
A Laravel package to monitor queue logs.
README 文档
README
A Laravel package for real-time monitoring of queues with stats on processing time, failed jobs, and retry status.
Features
- Real-time queue monitoring.
- Detailed stats on processing time and retries.
- Notifications for failed jobs.
Installation
- Require the package via Composer
composer require MattYeend/queue-monitor
- Publish the configuration, views, and migrations:
php artisan vendor:publish --provider="MattYeend\QueueMonitoring\QueueMonitoringServiceProvider" - Run the migrations to create the necessary database table:
php artisan migrate
- Access the dashboard at
/queue-monitor(or a custom route if configured)
Usage
- Queue Monitoring Dashboard
Once installed, the package provides a monitoring dashboard accessible at
/queue-monitor(or a custom route specified inconfig/queue-monitor.php). The dashboard displays:
- The list of queues being monitored.
- The number of jobs processed.
- The number of failed jobs.
- The average processing time for each queue.
- Automatically Updating Queue Statistics To update queue statistics after job processing:
- Inject the
QueueMonitorServiceinto your job classes or relevant services. - Use the
updateQueueStatusmethod to log the queue name, processing time, and failure status. Example Integration in a Job:
use MattYeend\QueueMonitoring\Services\QueueMonitorService; class ExampleJob implements ShouldQueue { public function handle(QueueMonitorService $service) { $queueName = 'example-queue'; $startTime = microtime(true); try { // Performs job processing } catch (\Exception $e) { $service->updateQueueStatus($queueName, 0, true); // Log a failed job throw $e; } $endTime = microtime(true); $processingTime = ($endTime - $StartTime) * 1000; // Convert to milliseconds $service->updateQueueStatus($queueName, $processingTime, false); // Log a successful job } }
- Customising the Dashboard
You can customise the dashboard view by modifying the published Blade file
resources/views/vendor/queue-monitor/dashboard.blade.php - Custom Route
The change the route for the dashboard, edit the
dashboard_routevalue in the configuration file'dashboard_route' => '/admin/queue-status' - Notifications for Failed Jobs To enable email notifications for failed jobs:
- Add the following to your
.envfile:QUEUE_MONITOR_NOTIFICATION_EMAIL=devops@yourcompany.com - The configured email address will receive alerts whenever a job fails in a monitored queue.
Configuration
.env File
To configure email notifications for failed jobs, add the following line to your .env file:
QUEUE_MONITOR_NOTIFICATION_EMAIL=devops@yourcompany.com
This will be used to send notifications for failed jobs. If not set, it will default to admin@example.com.
Custom Dashboard Route
To change the default URL route, modify the config/queue-monitor.php file. For example
'dashboard_route' => '/admin/queue-status',
Tests
Setting Up the Test Environment
- Install Dependencies
composer install
- Configure your environment
Ensure your
.envfile is set up for testing. By default, theTestCaseclass configures an in-memory SQLite database for testing, so no additional setup is required.
Running the Test
- Run all tests
php artisan test
or:
./vendor/bin/phpunit
License
This package is licensed under the MIT License.
Contributing
Feel free to fork the repository and submit pull requests for improvements or new features!
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-01-14