Laravel Pulse Dashboard Monitoring
April 1, 2024
•
13 min read
Introduction
Laravel Pulse is a new package for monitoring application performance and health. It provides a beautiful dashboard for viewing metrics like request times, database queries, queue jobs, and more.
Installation
composer require laravel/pulse
php artisan vendor:publish --provider="Laravel\Pulse\PulseServiceProvider"
php artisan migrate
Dashboard
Access the Pulse dashboard:
// routes/web.php
Route::group(['middleware' => ['auth']], function () {
Pulse::routes();
});
Configure dashboard cards in config/pulse.php:
'cards' => [
Pulse::cards('Requests', ['method' => 'GET', 'uri' => '/api/*']),
Pulse::cards('Slow Requests', ['threshold' => 1000]),
Pulse::cards('Database Queries'),
Pulse::cards('Exceptions'),
Pulse::cards('Queue Jobs'),
],
Recording Metrics
Pulse automatically records:
- HTTP requests and response times
- Database queries and slow queries
- Exceptions and errors
- Queue job processing
- Server utilization
Custom Cards
Pulse::card(function ($card) {
$card->view('pulse.cards.users', [
'title' => 'Active Users',
'total' => User::where('last_active', '>', now()->subMinutes(5))->count(),
]);
});
Alerts
Pulse::check(function ($record) {
$slowRequests = $record->srequests()
->where('duration', '>', 2000)
->count();
if ($slowRequests > 100) {
Pulse::alert('Too many slow requests', $slowRequests);
}
});
Summary
Laravel Pulse provides an excellent way to monitor your Laravel application's performance. With its customizable cards and automatic recording of metrics, you can quickly identify performance issues and monitor application health.
For more information, check out our other tutorials on Laravel Octane and Laravel Forge.