$ lexprog.com

// notes from an old coder -- php, databases, and the occasional rant

[September 28, 2025] Laravel

Laravel Nightwatch: Monitoring

Laravel Nightwatch: Monitoring

────────────────────────────────────────────────────────

Laravel Nightwatch: Monitoring

Tip: Install Nightwatch

composer require laravel/nightwatch

Gotcha: Real-Time Monitoring

Nightwatch provides real-time visibility into your application's health.

Tip: Performance Tracking

Tracks slow queries, memory usage, and request times automatically.

Gotcha: Error Alerting

Configurable alerts for exceptions, slow requests, and queue failures.

Tip: Dashboard

Web dashboard with charts, logs, and performance metrics.

Gotcha: Data Retention

Configure how long monitoring data is stored. Longer retention = more storage.

Tip: Use route:cache Carefully

php artisan route:cache is fast, but it doesn't work with closure-based routes. Every time you cache routes, Laravel serializes them. If you have Route::redirect() or closure callbacks, the cache breaks. Stick to controller-based routes in production.

Tip: Model APP_KEY Rotation

Rotating APP_KEY invalidates all encrypted data — cookies, encrypted DB columns, and password reset tokens. If you must rotate (e.g., after a leak), plan a migration that re-encrypts existing data with the new key.

Gotcha: Local Scope Leaks

Global scopes defined in booted() apply to ALL queries on that model — including relationships. An innocent User::all() in admin panel might exclude soft-deleted users if a global scope is active.

Senior Insight

Nightwatch is Laravel's answer to production monitoring, and it fills a genuine gap. But monitoring tools are only as good as the alerts they generate. I've seen teams configure alerts for every possible metric, resulting in alert fatigue where critical notifications are ignored. My approach: start with monitoring CPU usage, queue length, 5xx error rate, and average response time. Add metrics slowly, and every alert must have a documented runbook.

Source: Laravel News (https://laravel-news.com/), Freek.dev (https://freek.dev/tags/laravel), Spatie Blog (https://spatie.be/blog)

────────────────────────────────────────────────────────
<-- back to posts