✅ Quickly set up a health check page for your Laravel application
- Inspired by Levelsio's Podcast with Lex Friedman and copied from All Goods
Health Check Passed | We Have Some issues |
---|---|
You can install the package via composer:
composer require mrtsec/laravel-health-check
After installation, you can access the health check page at /health
.
Publish the configuration file:
php artisan vendor:publish --provider="MRTSec\HealthCheck\HealthCheckServiceProvider"
This will create a health-check.php
file in your config
directory. Here's an explanation of the configuration options:
<?php
use MRTSec\HealthCheck\Checkers\DatabaseConnectionChecker;
use MRTSec\HealthCheck\Checkers\DatabaseQueryChecker;
use MRTSec\HealthCheck\Checkers\MigrationStatusChecker;
use MRTSec\HealthCheck\Checkers\CacheChecker;
use MRTSec\HealthCheck\Checkers\DiskSpaceChecker;
use MRTSec\HealthCheck\Checkers\LogFileChecker;
return [
// The route prefix for the health check page
'route_prefix' => 'health',
// Middleware to apply to the health check route
'middleware' => ['web'],
// Define your health checks here
'checkers' => [
'Database Connection' => [
'class' => DatabaseConnectionChecker::class,
'config' => [],
],
[...]
],
];
You can add, remove, or modify the health checks in the checkers
array. Each check is defined by a key-value pair where:
- The key is the name of the check displayed on the health check page.
- The value is an array containing:
class
: The fully qualified class name of the checker.config
: An array of configuration options specific to that checker.
To add a custom check:
- Create a new checker class that implements the
MRTSec\HealthCheck\Contracts\HealthCheckerInterface
. - Add your checker to the
checkers
array in the configuration file.
Example of adding a custom checker:
use App\HealthCheckers\MyCustomServiceChecker;
'checkers' => [
// ... existing checkers ...
'My Custom Service' => [
'class' => MyCustomServiceChecker::class,
'config' => [
// Any configuration your checker might need
],
],
],
- DatabaseConnectionChecker: Verifies the database connection.
- DatabaseQueryChecker: Performs a simple database query.
- MigrationStatusChecker: Checks if all migrations are up to date.
- CacheChecker: Verifies that the cache system is working.
- DiskSpaceChecker: Checks available disk space.
- LogFileChecker: Ensures the log file is writable.
Please see CHANGELOG for more information on what has changed recently.
The MIT License (MIT). Please see License File for more information.