spatie/uptime-monitor-app
Laravel-based PHP app to monitor website uptime and SSL certificate expiry. Notifies you when sites go down or recover, and before certificates expire, via Slack or email. Easy to install with Composer and runs via Laravel scheduler/cron.
Installation:
composer create-project spatie/uptime-monitor-app uptime-monitor
cd uptime-monitor
php artisan key:generate
Configuration:
.env to set APP_URL, MAIL_* (or SLACK_*) credentials, and database settings.php artisan migrate
First Use Case:
php artisan uptime:monitor --name="My Website" --url="https://example.com" --notify-via="mail"
php artisan uptime:check
config/uptime-monitor.php: Core settings (check intervals, thresholds).app/Console/Commands/: CLI commands (CheckUptimeCommand, MonitorCommand).app/Notifications/: Notification logic (extend for custom channels).Monitoring Setup:
php artisan uptime:monitor to add/remove monitors dynamically.staging, production) via tags:
php artisan uptime:monitor --name="API" --url="https://api.example.com" --tags="api,production"
Check Scheduling:
config/uptime-monitor.php:
'check_every_minutes' => 5,
'notify_after_minutes' => 2,
app/Console/Kernel.php):
$schedule->command('uptime:check')->everyFiveMinutes();
Notification Channels:
Spatie\UptimeMonitor\Notifications\MonitorNotification for custom channels (e.g., Discord, PagerDuty).'notifications' => [
'slack' => [
'webhook_url' => env('SLACK_WEBHOOK_URL'),
'channel' => '#alerts',
],
],
SSL Monitoring:
config/uptime-monitor.php:
'ssl' => [
'check_every_days' => 7,
'notify_days_before_expiration' => 30,
],
php artisan uptime:monitor --name="SSL Cert" --url="https://example.com" --check-ssl
Laravel Integration:
laravel-uptime-monitor package for deeper Laravel integration (e.g., tie notifications to Laravel’s event system).use Spatie\UptimeMonitor\Models\Monitor;
$monitors = Monitor::all();
API Access:
Route::get('/api/monitors', function () {
return Monitor::with('notifications')->get();
});
Logging:
app/Providers/AppServiceProvider to log checks:
Monitor::created(function ($monitor) {
Log::info("New monitor added: {$monitor->name}");
});
Deprecated Package:
spatie/laravel-uptime-monitor for active development.PHP 7.3+ Compatibility:
composer.json (e.g., phpunit/phpunit).Notification Delays:
php artisan uptime:check --force
Database Locking:
check_every_minutes or use queue workers:
$schedule->command('uptime:check')->everyMinute()->withoutOverlapping();
Check Logs:
.env (APP_DEBUG=true) and check storage/logs/laravel.log.tail -f storage/logs/laravel.log
Manual Checks:
php artisan uptime:check --monitor=1
SSL Issues:
openssl s_client -connect example.com:443 -servername example.com | openssl x509 -noout -dates
Custom Notifications:
Spatie\UptimeMonitor\Notifications\MonitorNotification:
namespace App\Notifications;
use Spatie\UptimeMonitor\Notifications\MonitorNotification;
class CustomNotification extends MonitorNotification {
public function via($notifiable) {
return ['custom-channel'];
}
}
Check Logic:
Spatie\UptimeMonitor\CheckMonitorJob to add custom HTTP headers or assertions:
public function handle() {
$response = Http::withHeaders(['X-Custom-Header' => 'value'])->get($this->monitor->url);
// Custom logic...
}
Dashboard:
Monitor model:
// Example: List monitors with last check status
$monitors = Monitor::with(['notifications' => function($query) {
$query->latest()->limit(1);
}])->get();
Queue Workers:
$schedule->job(new \Spatie\UptimeMonitor\CheckMonitorJob($monitor))->everyFiveMinutes();
Environment Variables:
.env variables are loaded (e.g., SLACK_WEBHOOK_URL). Use:
php artisan config:clear
after changes.Timezones:
APP_TIMEZONE in .env to match your monitoring expectations (e.g., UTC).HTTPS Enforcement:
http to https. Use --check-ssl carefully for HTTP-only sites.How can I help you explore Laravel packages today?