Back to Blog
Server Monitoring and Alerting: Knowing Before Users Do
You Can't Fix What You Can't See
Production systems need monitoring. Without it, you learn about problems from angry users. Good monitoring catches issues early and provides data for debugging.
Key Metrics
System Metrics
- CPU usage
- Memory usage
- Disk space and I/O
- Network traffic
Application Metrics
- Request rate
- Error rate
- Response time (p50, p95, p99)
- Queue depth and processing time
Business Metrics
- Active users
- Transaction volume
- Conversion rates
Laravel Pulse Integration
// Built-in monitoring with Laravel Pulse
composer require laravel/pulse
php artisan pulse:install
// Access at /pulse
// Shows: slow requests, exceptions, queues, cache stats
External Monitoring
// Health check endpoint
Route::get('/health', function () {
$checks = [
'database' => $this->checkDatabase(),
'cache' => $this->checkCache(),
'queue' => $this->checkQueue(),
'storage' => $this->checkStorage(),
];
$healthy = collect($checks)->every(fn ($c) => $c['status'] === 'ok');
return response()->json([
'status' => $healthy ? 'healthy' : 'degraded',
'checks' => $checks,
], $healthy ? 200 : 503);
});
Alerting Rules
// Example Prometheus alerting rules
groups:
- name: laravel
rules:
- alert: HighErrorRate
expr: rate(http_requests_total{status=~"5.."}[5m]) > 0.1
for: 5m
labels:
severity: critical
annotations:
summary: High error rate detected
- alert: SlowResponseTime
expr: histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m])) > 2
for: 10m
labels:
severity: warning
Log Aggregation
// Structured logging
Log::info('Order processed', [
'order_id' => $order->id,
'total' => $order->total,
'processing_time_ms' => $timer->elapsed(),
]);
// Ship to centralized logging (ELK, Datadog, etc.)
Conclusion
Monitoring is essential for production systems. Track system, application, and business metrics. Set up alerts for anomalies. Aggregate logs for debugging. Know about problems before your users do.
Related Articles
Need Help With Your Project?
I respond to all inquiries within 24 hours. Let's discuss how I can help build your production-ready system.
Get In Touch