Registering probes

The simplest way to choose probes is the health.probes list in config/cinder.php. Each entry is one of:

use Cinderwatch\Health\Probes\DiskUsageProbe;
use Cinderwatch\Laravel\Health\Probes;

'probes' => [
    // A class name — framework services are injected automatically.
    Probes\DatabaseConnectionProbe::class,

    // A class name with named constructor arguments.
    DiskUsageProbe::class => ['path' => '/', 'warnAbovePercent' => 70, 'failAbovePercent' => 90],

    // A boolean switches an entry on or off (handy with env()).
    Probes\HorizonProbe::class => env('HORIZON_ENABLED', true),

    // The same probe twice, with its own id and title.
    ['probe' => Probes\DatabaseConnectionProbe::class, 'with' => ['connection' => 'replica'], 'id' => 'replica-db', 'title' => 'Replica database'],
],

Registered probes run when php artisan cinder:health executes, and on each endpoint request when inspect_on_request is enabled.

Registering in code

When the list depends on runtime state, replace it from a service provider:

use Cinderwatch\Health\GuardedProbe;
use Cinderwatch\Health\Probes\DiskUsageProbe;
use Cinderwatch\Laravel\Facades\Cinder;
use Cinderwatch\Laravel\Health\Probes\DatabaseConnectionProbe;

public function boot(): void
{
    Cinder::probes([
        $this->app->make(DatabaseConnectionProbe::class),
        new DiskUsageProbe(path: '/', warnAbovePercent: 80),
    ]);
}

Use Cinder::health()->register($probe) to add a single probe without replacing the list. A probe with the same id as an existing one replaces it.

Ids and titles

Every probe has a stable id (for example database or disk-usage) and a human-readable title. Use AliasedProbe to change them:

use Cinderwatch\Health\AliasedProbe;

new AliasedProbe($this->app->make(DatabaseConnectionProbe::class, ['connection' => 'replica']), 'replica-db', 'Replica database');

Conditional probes

Wrap a probe in GuardedProbe to report it as not applicable unless a condition holds:

new GuardedProbe(
    new DiskUsageProbe,
    fn (): bool => app()->environment('production'),
    'Disk usage is only checked in production.',
);

Running probes manually

php artisan cinder:health

The command exits successfully by default (see Introduction). Pass --strict when you need a non-zero exit.

Or in code:

$snapshot = Cinder::health()->inspect();

Writing a custom probe

Implement Cinderwatch\Health\Probe:

use Cinderwatch\Health\Observation;
use Cinderwatch\Health\Probe;

final class PaymentsApiProbe implements Probe
{
    public function id(): string
    {
        return 'payments-api';
    }

    public function title(): string
    {
        return 'Payments API';
    }

    public function examine(): Observation
    {
        // check your dependency...

        return Observation::healthy('Reachable');
    }
}

Observation also offers degraded($summary, $detail), unhealthy($summary, $detail) and notApplicable($reason). An exception thrown from examine() is reported as Errored. Register custom probes the same way as the built-in ones.