Skip to content

prevplan/laravel-heartbeat-status

Repository files navigation

Monitor Laravel queue and schedule status

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A simple package to monitor the queue heartbeat and the schedule of a Laravel Site.
It provides a route with a status and a 200 or 503 HTTP state that can be monitored by uptime services such as upptime.

Tested with Laravel 9 + 10.

Installation

You can install the package via composer:

composer require prevplan/laravel-heartbeat-status

The standard URL is yoursite.com/heartbeat. If you want to change this, add

Route::heartbeat_status('new-folder');

to your routes/web.php.

You can optionally publish the config file with:

php artisan vendor:publish --tag="laravel-heartbeat-status-config"

This is the contents of the published config file:

return [
    /*
    |--------------------------------------------------------------------------
    | Heartbeat Interval Time
    |--------------------------------------------------------------------------
    |
    | Time in minutes between queued heartbeatStatusCommand jobs.
    |
    */
    'heart-rate' => env('HEARTBEAT_HEART_RATE', 2),

    /*
    |--------------------------------------------------------------------------
    | Heartbeat Emergency Time
    |--------------------------------------------------------------------------
    |
    | Time in minutes to report failure/change to status 503, if the
    | last heartbeatStatusCommand is older than this value
    |
    */
    'emergency_time' => env('HEARTBEAT_EMERGENCY', 5),

    /*
    |--------------------------------------------------------------------------
    | Schedule Leeway
    |--------------------------------------------------------------------------
    |
    | Time for schedule running tolerance in seconds
    |
    */
    'schedule_leeway' => env('HEARTBEAT_SCHEDULE_LEEWAY', 10),

    /*
    |--------------------------------------------------------------------------
    | Queue Leeway
    |--------------------------------------------------------------------------
    |
    | Time for queue running tolerance in seconds
    |
    */
    'queue_leeway' => env('HEARTBEAT_QUEUE_LEEWAY', 20),
];

Optionally, you can publish the views using

php artisan vendor:publish --tag="laravel-heartbeat-status-views"

Usage

The status page is automatically published under yoursite.com/heartbeat or another URL if you’ve changed it.
It checks the last run of the schedule and the queue.

If everything works fine, it responds to a 200 HTTP state. If there is a problem a 503 HTTP state will be shown.
You can monitor this heartbeat page with upptime or another uptime service of your choice.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.