mortenscheel/laravel-heartbeat

监控 Laravel 队列性能

0.9.1 2021-10-13 07:07 UTC

This package is auto-updated.

Last update: 2024-09-13 13:55:50 UTC


README

Latest Version on Packagist Total Downloads

一种简单的方法来检测您的队列工作是否挂起或无法跟上。

安装

通过 Composer

$ composer require mortenscheel/laravel-heartbeat

配置

发布配置

$ php artisan vendor:publish --tag=heartbeat-config

默认配置

<?php
return [
    /*
     * When enabled, Laravel's sceduler will run the heartbeat:monitor
     * command every minute, which will:
     * 1. Dispatch heartbeat jobs on the configured queues.
     * 2. Send an email to the configured recipients if a
     *    queue exceeds the maximum time between heartbeats.
     */
    'enabled'               => env('HEARTBEAT_ENABLED', false),
    /*
     * Maximum seconds between heartbeats, unless overridden.
     */
    'default_threshold'     => 120,
    /*
     * Which queues to monitor.
     * To set a custom threshold, use the format
     * 'queue_name' => maximum_seconds,
     */
    'queues'                => [
        'default',
    ],
    /*
     * Recipients will receive an "Unhealthy heartbeat warning" e-mail
     * when one or more queues exceed the configured threshold
     */
    'recipients'            => [
    ],
    /*
     * Minimum time between identical e-mail warnings
     */
    'deduplication_minutes' => 1440,
    /*
     * Heartbeats are stored in the application cache (for 24 hours) with this cache prefix
     */
    'cache_prefix'          => 'heartbeat',
];

使用方法

通过将以下变量添加到 .env 中启用心跳检测:

HEARTBEAT_ENABLED=true

如果 Laravel 的调度器通过 cron 运行,则 heartbeat:monitor 命令将每分钟自动运行。

要查看队列心跳的当前状态,您可以在控制台中手动运行 heartbeat:monitor

$ php artisan heartbeat:monitor
+---------+----------------+-------------+
| Queue   | Last heartbeat | Max allowed |
+---------+----------------+-------------+
| default | 1 minute ago   | 2 minutes   |
| high    | 1 minute ago   | 2 minutes   |
| low     | 1 minute ago   | 3 minutes   |
| encode  | 2 minutes ago  | 30 minutes  |
+---------+----------------+-------------+

变更日志

请参阅 changelog 了解最近更改的详细信息。

测试

$ composer test

贡献

请参阅 contributing.md 了解详细信息和一个待办事项列表。

安全性

如果您发现任何与安全相关的问题,请通过电子邮件发送到 morten@mortenscheel.com,而不是使用问题跟踪器。

致谢

许可

许可。请参阅 许可文件 了解更多信息。