Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Uptime Monitor App Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer create-project spatie/uptime-monitor-app uptime-monitor
    cd uptime-monitor
    php artisan key:generate
    
  2. Configuration:

    • Edit .env to set APP_URL, MAIL_* (or SLACK_*) credentials, and database settings.
    • Run migrations:
      php artisan migrate
      
  3. First Use Case:

    • Add a monitor via the CLI:
      php artisan uptime:monitor --name="My Website" --url="https://example.com" --notify-via="mail"
      
    • Trigger a manual check:
      php artisan uptime:check
      

Key Files to Review

  • config/uptime-monitor.php: Core settings (check intervals, thresholds).
  • app/Console/Commands/: CLI commands (CheckUptimeCommand, MonitorCommand).
  • app/Notifications/: Notification logic (extend for custom channels).

Implementation Patterns

Workflows

  1. Monitoring Setup:

    • Use php artisan uptime:monitor to add/remove monitors dynamically.
    • Group monitors by environment (e.g., staging, production) via tags:
      php artisan uptime:monitor --name="API" --url="https://api.example.com" --tags="api,production"
      
  2. Check Scheduling:

    • Configure checks via config/uptime-monitor.php:
      'check_every_minutes' => 5,
      'notify_after_minutes' => 2,
      
    • Schedule via Laravel’s scheduler (app/Console/Kernel.php):
      $schedule->command('uptime:check')->everyFiveMinutes();
      
  3. Notification Channels:

    • Extend Spatie\UptimeMonitor\Notifications\MonitorNotification for custom channels (e.g., Discord, PagerDuty).
    • Example for Slack:
      'notifications' => [
          'slack' => [
              'webhook_url' => env('SLACK_WEBHOOK_URL'),
              'channel' => '#alerts',
          ],
      ],
      
  4. SSL Monitoring:

    • Enable SSL checks in config/uptime-monitor.php:
      'ssl' => [
          'check_every_days' => 7,
          'notify_days_before_expiration' => 30,
      ],
      
    • Add SSL monitors:
      php artisan uptime:monitor --name="SSL Cert" --url="https://example.com" --check-ssl
      

Integration Tips

  • Laravel Integration:

    • Use the underlying laravel-uptime-monitor package for deeper Laravel integration (e.g., tie notifications to Laravel’s event system).
    • Access monitor data via Eloquent:
      use Spatie\UptimeMonitor\Models\Monitor;
      $monitors = Monitor::all();
      
  • API Access:

    • Expose monitor status via a custom API endpoint:
      Route::get('/api/monitors', function () {
          return Monitor::with('notifications')->get();
      });
      
  • Logging:

    • Extend app/Providers/AppServiceProvider to log checks:
      Monitor::created(function ($monitor) {
          Log::info("New monitor added: {$monitor->name}");
      });
      

Gotchas and Tips

Pitfalls

  1. Deprecated Package:

    • The package is archived (last release: 2017). Use spatie/laravel-uptime-monitor for active development.
    • Workarounds: Fork the repo or patch locally for critical fixes.
  2. PHP 7.3+ Compatibility:

    • May require manual updates to composer.json (e.g., phpunit/phpunit).
    • Test thoroughly after upgrading PHP versions.
  3. Notification Delays:

    • If using Slack/email, ensure webhooks/SMTP are configured correctly. Test with:
      php artisan uptime:check --force
      
  4. Database Locking:

    • High-frequency checks may cause database contention. Adjust check_every_minutes or use queue workers:
      $schedule->command('uptime:check')->everyMinute()->withoutOverlapping();
      

Debugging

  • Check Logs:

    • Enable debug mode in .env (APP_DEBUG=true) and check storage/logs/laravel.log.
    • Tail logs in real-time:
      tail -f storage/logs/laravel.log
      
  • Manual Checks:

    • Force a check for a specific monitor:
      php artisan uptime:check --monitor=1
      
  • SSL Issues:

    • Verify SSL checks with:
      openssl s_client -connect example.com:443 -servername example.com | openssl x509 -noout -dates
      

Extension Points

  1. Custom Notifications:

    • Extend Spatie\UptimeMonitor\Notifications\MonitorNotification:
      namespace App\Notifications;
      use Spatie\UptimeMonitor\Notifications\MonitorNotification;
      
      class CustomNotification extends MonitorNotification {
          public function via($notifiable) {
              return ['custom-channel'];
          }
      }
      
  2. Check Logic:

    • Override 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...
      }
      
  3. Dashboard:

    • Build a custom dashboard using the Monitor model:
      // Example: List monitors with last check status
      $monitors = Monitor::with(['notifications' => function($query) {
          $query->latest()->limit(1);
      }])->get();
      
  4. Queue Workers:

    • Offload checks to a queue (e.g., Redis) to avoid blocking:
      $schedule->job(new \Spatie\UptimeMonitor\CheckMonitorJob($monitor))->everyFiveMinutes();
      

Configuration Quirks

  • Environment Variables:

    • Ensure .env variables are loaded (e.g., SLACK_WEBHOOK_URL). Use:
      php artisan config:clear
      
      after changes.
  • Timezones:

    • Set APP_TIMEZONE in .env to match your monitoring expectations (e.g., UTC).
  • HTTPS Enforcement:

    • SSL checks may fail if the server redirects http to https. Use --check-ssl carefully for HTTP-only sites.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport