anourvalar/laravel-health

Additional Checks for Laravel Health (Spatie)

1.13.0 2024-11-18 12:40 UTC

README

Installation

composer require anourvalar/laravel-health

Checks for spatie/laravel-health

FilesystemCheck

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\FilesystemCheck::new()->disks(['s3' => ($checkPublicUrl = true)]),
]);

OpcacheCheck

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\OpcacheCheck::new(),
]);

PusherCheck

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\PusherCheck::new()->connection(null), // default connection
]);

QueueFailedCheck

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\QueueFailedCheck::new(),
]);

XdebugCheck

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\XdebugCheck::new(),
]);

SSL Certificate

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\SSLCertCheck::new()
      ->url('google.com')
      ->warnWhenExpiringDay(10)
      ->failWhenExpiringDay(2),
]);

Cpu Load

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\CpuLoadCheck::new()->failWhenLoadIsHigher(
        2.5, // last minute
        2.0, // last 5 minutes
        1.5  // last 15 minutes
    ),
]);

Gzip

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\GzipCheck::new()
        ->shouldBeGzipped('/')
        ->shouldNotBeGzipped('/image.png'),
]);

Reverse Proxy Security

First, you need to register a route for the checker.

Route::any('/health-ping', HealthPingController::class);
\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\ReverseProxySecurityCheck::new()->url('/health-ping'),
]);

HTTP -> HTTPS 301 redirect

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\Http2HttpsCheck::new()
        ->shouldBeRedirected(['/', '/image.png']),
]);

WWW -> none WWW 301 redirect

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\Www2NoneCheck::new()
        ->shouldBeRedirected(['/', '/image.png']),
]);

Mailer

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\MailerCheck::new()
        ->mailer(null), // default
]);

Sentry

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\SentryCheck::new(),
]);

Directory Permissions

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\DirectoryPermissionsCheck::new()
        ->writable(storage_path('logs'))
        ->notWritable(app_path('')),
]);

CORS

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\CorsCheck::new()
        ->allowed('https://good.com')
        ->disallowed('https://evil.com')
        ->url('api/sanctum/csrf-cookie'), // target endpoint
]);

Cache Headers

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\CacheHeadersCheck::new()
        ->shouldBeCached('/image.png')
        ->shouldNotBeCached('/'),
]);

Root (user)

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\RootCheck::new(),
]);

FastCGI

First, you need to register a route for the checker.

Route::any('/health-ping', HealthPingController::class);
\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\FastCGICheck::new()->url('/health-ping'),
]);

Queue size

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\QueueSizeCheck::new()
        ->add(['connection' => null, 'name' => null, 'max_size' => 200]),
]);

Octane server

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\OctaneCheck::new(),
]);

Redis Config

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\RedisConfigCheck::new(),
]);

HTTP/2

\Spatie\Health\Facades\Health::checks([
    \AnourValar\LaravelHealth\HttpV2::new()->urls('/'),
]);