Laravel Pulse

repository·1.x·Indexed 23 days ago

https://github.com/laravel/pulse

A real-time application performance monitoring (APM) tool and dashboard for Laravel applications. It provides visibility into application health and performance metrics, featuring CLI commands for data processing (pulse:work), snapshots (pulse:check), and data management (pulse:clear, pulse:restart). The tool allows for custom data recording via the Entry class, configurable ingest drivers (storage, redis, null), and customizable system metric detection for CPU and memory.

Tokens
3.1K
Snippets
4
Records
32
Agent score
81%

What's inside Laravel Pulse

  1. What is Laravel Pulse

    1.x
    Laravel Pulse is a real-time application performance monitoring tool and dashboard designed specifically for Laravel applications. It allows you to monitor your application's health, performance, and usage metrics through a dedicated dashboard.
  2. Migrate from Pulse Beta to 1.x

    1.x

    When upgrading from a Beta version of Laravel Pulse to version 1.x, several breaking changes and architectural shifts occurred. Ensure you address the following:

    • SQL Highlighting: Configuration for SQL highlighting has moved to the dashboard component. If you previously disabled SQL highlighting via configuration, you must now manage this through the dashboard component.
    • Database Schema (IDs): Pulse tables now include auto-incrementing IDs. This is necessary for environments like PlanetScale that require a unique key on every table.
    • Database Schema (Column Types): TEXT columns in pulse_ tables have been upgraded to MEDIUMTEXT to support longer content, such as extensive SQL queries.
    • Migration Ownership: Pulse migrations are now published directly to your application. This allows for full control over the migration lifecycle.
    • Command Behavior: The pulse:check command now dispatches events approximately every second. If you are performing work on specific intervals within this command, it is recommended to use the new throttle function to manage execution frequency.
  3. Configure Pulse authorization

    1.x

    By default, Pulse uses a Gate named viewPulse to authorize access to the dashboard. In the default service provider implementation, this gate is defined to return true only when the application environment is local.

    You can customize this authorization logic in your own AuthServiceProvider by defining the viewPulse gate.

  4. Publish Pulse configuration, views, and migrations

    1.x

    To customize Pulse, you can publish its configuration, dashboard views, and database migrations using the following Artisan commands:

    Publish Configuration:

    php artisan vendor:publish --tag=pulse-config

    Publish Dashboard Views:

    php artisan vendor:publish --tag=pulse-dashboard

    Publish Migrations:

    php artisan vendor:publish --tag=pulse-migrations
  5. Configure Exception Recorder location

    1.x
    The Exceptions recorder can optionally include the file location (file path and line number) in its recorded data. This is controlled via the pulse.recorders.Laravel\Pulse\Recorders\Exceptions.location configuration key. If this key is set to true, Pulse will attempt to resolve the specific file and line where the exception occurred, attempting to skip vendor files to find the relevant application code.
  6. Configure Pulse dashboard routing

    1.x

    You can customize how the Pulse dashboard is accessed via the config/pulse.php configuration file.

    • path: The URL prefix for the dashboard (e.g., pulse).
    • domain: An optional domain to restrict the dashboard to.
    • middleware: An array of additional middleware to apply to the Pulse route group.
  7. Configure Pulse ingest drivers

    1.x

    Pulse uses ingest drivers to handle how data is collected and stored. You can configure the driver in your config/pulse.php file using the ingest.driver key.

    Available drivers:

    • storage: Uses the StorageIngest implementation.
    • redis: Uses the RedisIngest implementation.
    • null: Uses the NullIngest implementation (useful for disabling data collection without disabling Pulse entirely).
  8. Filter items before storage

    1.x
    Use the filter() method to define a callback that determines whether a specific Entry or Value should be stored. If the callback returns false, the item is discarded during the ingestion process.
  9. Remember a user ID

    1.x
    Use rememberUser() to manually set the ID of the user currently being tracked. This is useful in contexts where the standard authentication guard might not be available or when tracking background jobs.
  10. Record a value with `set()`

    1.x

    Use the set() method to log a string-based value (a Value) to Pulse. This is typically used for tracking state or text-based information.

    Arguments:

    • type: A UnitEnum, BackedEnum, or string representing the category.
    • key: A UnitEnum, BackedEnum, or string representing the specific key.
    • value: The string value to record.
    • timestamp: An optional DateTimeInterface, int, or null (defaults to now()).
  11. Customize user data displayed in the Pulse dashboard

    1.x

    By default, Pulse attempts to resolve user information (name, email/extra, and avatar) from your Authenticatable model. If your user model uses different property names or you want to provide custom data, you can use setFieldResolver to define how user fields are mapped.

    The resolver callback must return an object with the following structure:

    • name: (string) The display name of the user.
    • extra: (string, optional) Additional information, typically the email address.
    • avatar: (string, optional) A URL to the user's avatar image.
  12. Configure user resolution for Pulse

    1.x

    Pulse needs to know how to map user IDs to user details (name, email, avatar) for the dashboard. Use the user() method to provide a callback that resolves an Authenticatable user into an array of user details.

    Expected return format:

    ['name' => '...', 'email' => '...', 'avatar' => '...', 'extra' => '...']