Skip to content

Health Checks

The application uses spatie/laravel-health for monitoring system health. Health checks run every minute through the scheduler and monitor critical application services.

The following health checks are registered by default in HealthServiceProvider:

CheckDescriptionEnvironment
DatabaseVerifies database connectivityProduction only
QueueVerifies queue system is operationalAll
CacheVerifies cache system is operationalAll
ScheduleVerifies scheduled tasks have run recentlyAll
Debug ModeEnsures debug mode is disabledNon-local
Optimized AppEnsures app is optimizedNon-local
Security AdvisoriesChecks for known package vulnerabilitiesAll
Directory SearchVerifies Northwestern Directory Search APIAll

Additional checks are available for services like Redis, Horizon, Octane, and more. See the available checks documentation for a complete list. To add a check, register it in the HealthServiceProvider.

A public health check endpoint is available for external monitoring systems.

Endpoint: GET /api/health

Authentication: None

Response:

{
"finishedAt": 1703299200,
"checkResults": [
{
"name": "database",
"label": "Database",
"notificationMessage": "Database is operational",
"shortSummary": "OK",
"status": "ok",
"meta": {}
}
]
}

HTTP Status Codes:

CodeMeaning
200All health checks passing
503One or more health checks failing

Check Status Values:

StatusDescription
okCheck passed
warningCheck passed with warnings
failedCheck failed
crashedCheck threw an exception
skippedCheck was conditionally skipped

Health checks run every minute through the scheduler, but email notifications are disabled by default. To receive alerts when checks fail, enable notifications and configure a recipient email address.

Add the following to your .env file:

Terminal window
HEALTH_NOTIFICATIONS_ENABLED=true
HEALTH_NOTIFICATION_EMAIL=your-team@northwestern.edu

The application uses EloquentHealthResultStore to persist health check results in the database. This enables:

  • Viewing health status in the admin panel’s Platform Overview page
  • Historical tracking for trend analysis
  • Results available immediately after scheduler runs

Results are automatically pruned after 5 days to prevent unbounded database growth.

Create a new check class extending Spatie\Health\Checks\Check:

<?php
namespace App\Domains\Core\Health;
use Spatie\Health\Checks\Check;
use Spatie\Health\Checks\Result;
class CustomServiceCheck extends Check
{
protected ?string $label = 'Custom Service';
public function run(): Result
{
$result = Result::make();
try {
$isHealthy = $this->checkService();
if ($isHealthy) {
return $result
->ok()
->shortSummary('Service operational');
}
return $result
->failed('Service unavailable')
->shortSummary('Service down');
} catch (\Exception $e) {
return $result
->failed($e->getMessage())
->shortSummary('Check failed');
}
}
private function checkService(): bool
{
// Your health check logic here
return true;
}
}

Add your check to HealthServiceProvider:

Health::checks([
// ... existing checks
CustomServiceCheck::new(),
]);

Run checks only in specific environments:

CustomServiceCheck::new()
->if(App::isProduction()),

Or skip checks in certain environments:

CustomServiceCheck::new()
->unless(App::isLocal()),