Health Monitoring
Health monitoring using Spatie Health package with Laravel Telescope for debugging and performance analysis.
Overview
Section titled “Overview”The health monitoring system provides:
- Health check endpoints for load balancers and monitoring
- Dashboard UI for manual inspection
- Email notifications for failures (throttled)
- Historical data stored in database
Quick Start
Section titled “Quick Start”Check Health Status
Section titled “Check Health Status”# Via Artisan./vendor/bin/sail artisan health:check
# Via HTTPcurl http://localhost/healthAccess Dashboard
Section titled “Access Dashboard”Navigate to /health-dashboard (requires authentication).
Health Checks
Section titled “Health Checks”Configured Checks
Section titled “Configured Checks”| Check | Purpose | Threshold |
|---|---|---|
| Database | PostgreSQL connectivity | - |
| Cache | Redis connectivity | - |
| Disk Space | Available storage | Warn: 70%, Fail: 90% |
| Optimized App | Laravel optimization status | Production only |
| Debug Mode | APP_DEBUG is false | Production only |
| Environment | APP_ENV matches expected | Production only |
Check Results
Section titled “Check Results”Each check returns one of:
ok- Check passedwarning- Check passed with concernsfailed- Check failed
Endpoints
Section titled “Endpoints”JSON Endpoint
Section titled “JSON Endpoint”GET /health
Response (200 OK):{ "finishedAt": "2025-11-14T17:30:00Z", "checkResults": [ {"name": "Database", "status": "ok"}, {"name": "Cache", "status": "ok"}, {"name": "UsedDiskSpace", "status": "ok", "meta": {"used": "45%"}} ]}
Response (503 Service Unavailable):{ "finishedAt": "2025-11-14T17:30:00Z", "checkResults": [ {"name": "Database", "status": "failed", "message": "Connection refused"} ]}Dashboard
Section titled “Dashboard”GET /health-dashboardVisual dashboard showing:
- All check statuses
- Historical trends
- Failure details
Configuration
Section titled “Configuration”Health Config
Section titled “Health Config”File: config/health.php
return [ 'result_stores' => [ DatabaseHealthResultStore::class => [ 'keep_history_for_days' => 5, ], ],
'notifications' => [ 'enabled' => true, 'notifiable' => HealthNotifiable::class, 'channels' => ['mail'], 'throttle_notifications_for_minutes' => 60, ],];Environment Variables
Section titled “Environment Variables”# Notification emailHEALTH_NOTIFICATION_EMAIL=ops@example.com
# Database connection for health checksHEALTH_DB_CONNECTION=pgsqlLaravel Telescope
Section titled “Laravel Telescope”Overview
Section titled “Overview”Telescope provides debugging and monitoring for:
- Requests
- Commands
- Jobs
- Exceptions
- Logs
- Database queries
- Cache operations
- Notifications
Access
Section titled “Access”GET /telescopeRequires authentication in production.
Configuration
Section titled “Configuration”File: config/telescope.php
'enabled' => env('TELESCOPE_ENABLED', true),
'ignore_commands' => [ 'schedule:work', 'queue:work',],
'ignore_paths' => [ 'nova-api*', 'pulse*',],Data Retention
Section titled “Data Retention”Telescope data is pruned daily:
- Keeps last 14 days
- Preserves exception entries
- Runs via scheduler
$schedule->command('telescope:prune --hours=336')->daily();Monitoring Integration
Section titled “Monitoring Integration”AWS CloudWatch
Section titled “AWS CloudWatch”# Load balancer health checkHealthCheck: Path: /health Interval: 30 Timeout: 5 HealthyThreshold: 2 UnhealthyThreshold: 2DataDog
Section titled “DataDog”# DataDog agent check- name: volare_health url: https://api.volare.com/health check_interval: 30 alert_on_failure: truePrometheus
Section titled “Prometheus”# Prometheus scrape config- job_name: 'volare' metrics_path: '/health' static_configs: - targets: ['api.volare.com']Custom Health Checks
Section titled “Custom Health Checks”Creating a Check
Section titled “Creating a Check”use Spatie\Health\Checks\Check;use Spatie\Health\Checks\Result;
class AerTicketApiCheck extends Check{ public function run(): Result { try { $service = app(AerticketCabinetService::class); $service->testConnection();
return Result::make()->ok('AerTicket API is accessible');
} catch (\Exception $e) { return Result::make() ->failed("AerTicket API unreachable: {$e->getMessage()}"); } }}Registering Check
Section titled “Registering Check”use Spatie\Health\Facades\Health;
Health::checks([ // ... existing checks AerTicketApiCheck::new(),]);Alerting
Section titled “Alerting”Email Notifications
Section titled “Email Notifications”// Notifications sent when checks fail// Throttled to 1 per hour per check
class HealthNotifiable extends Notifiable{ public function routeNotificationForMail(): string { return config('health.notification_email'); }}Slack Integration (Optional)
Section titled “Slack Integration (Optional)”// Add Slack channel'channels' => ['mail', 'slack'],
// Configure webhookHEALTH_SLACK_WEBHOOK_URL=https://hooks.slack.com/...Troubleshooting
Section titled “Troubleshooting”Health Check Failing
Section titled “Health Check Failing”- Run check manually:
./vendor/bin/sail artisan health:check- Check specific service:
# Database./vendor/bin/sail artisan tinker>>> DB::connection()->getPdo();
# Cache>>> Cache::get('test');Dashboard Not Loading
Section titled “Dashboard Not Loading”- Check authentication
- Verify route registration
- Check middleware configuration
Telescope Not Recording
Section titled “Telescope Not Recording”- Check
TELESCOPE_ENABLED=true - Verify storage permissions
- Check database migration ran
Related Documentation
Section titled “Related Documentation”- Docker Health Monitoring - Container health
- Queue System - Queue monitoring