NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Alerts for Laravel

Registering checks

Register the checks your application supports, typically in a service provider’s boot():

use RoundlyConsulting\Alerts\Facades\Health;

Health::check(DiskUsageCheck::class);

// Or register several at once:
Health::checks([
    DiskUsageCheck::class,
    MemoryUsageCheck::class,
]);

// The HealthManager behind the facade is also injectable (see DI and actions):
app(\RoundlyConsulting\Alerts\HealthManager::class)->checks([DiskUsageCheck::class]);

Or list class names in the config — they are registered when the package boots:

// config/alerts.php
'checks' => [
    RoundlyConsulting\Alerts\Checks\DatabaseCheck::class,
    App\Health\DiskUsageCheck::class,
],

Register in every process

The registry lives in memory. The web app, the scheduler and every queue worker need the same checks registered, so do it in a service provider or the config. When a queued job runs a row whose key is not registered in that process, it throws InvalidHealthCheck::notRegistered().

One instance per key

Checks are stored by key(). Each check registers under a key derived from its class (database_check, http_ping_check, …), and registering a second instance under the same key replaces the first. To watch several targets with one class — built-in checks included — give each instance its own key with as(). The name follows the key:

use RoundlyConsulting\Alerts\Checks\DatabaseCheck;
use RoundlyConsulting\Alerts\Facades\Health;

Health::check(DatabaseCheck::make('mysql')->as('mysql_database'));   // name "Mysql Database"
Health::check(DatabaseCheck::make('pgsql')->as('pgsql_database'));

Health::for($team)->monitor('mysql_database')->everyMinute()->save();
Health::for($team)->run('pgsql_database');

Schedule and run such an instance by its key. Running a class registered under several keys by its class name throws InvalidHealthCheck::ambiguous(). A subclass that overrides key() keeps control of its key.

Inspecting the registry

use RoundlyConsulting\Alerts\Facades\Health;

Health::all(); // Collection<string, Check> keyed by check key

$check = Health::find('disk_usage_check');

$check->name();        // "Disk Usage Check"
$check->key();         // "disk_usage_check"
$check->description(); // "Perform Disk Usage Check and trigger notification when necessary."
$check->frequencies(); // ['* * * * *' => 'Every Minute', ...]
$check->tags();        // [] unless the class overrides tags()
  • name() — Str::headline of the class name, or of the key given to as(); key() — the class name in snake_case, or that key. Override either in your check.
  • description() — a translatable default sentence built from the name.
  • frequencies() — a cron ⇒ label map for select inputs: every minute, 5 and 10 minutes, hour, day, week, month and year. Labels pass through __(), so you can translate them.
  • Health::check() accepts a class name or an instance; anything that does not extend Check throws InvalidHealthCheck::doesntExtendBaseCheck().
  • Health::check() and Health::checks() return the manager, so registrations chain.

Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

More ways to support, including crypto

By donating, you agree to our donation terms.

Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.