108 lines
4.6 KiB
Markdown
108 lines
4.6 KiB
Markdown
---
|
|
title: Debug Dashboard
|
|
order: 2
|
|
---
|
|
|
|
# Debug Dashboard
|
|
|
|
In addition to logging the events to the console, you can also use a real-time dashboard that shows you all incoming connections, events and disconnects the moment they happen on your WebSocket server.
|
|
|
|

|
|
|
|
## Accessing the Dashboard
|
|
|
|
The default location of the WebSocket dashboard is at `/laravel-websockets`. The routes get automatically registered.
|
|
If you want to change the URL of the dashboard, you can configure it with the `path` setting in your `config/websockets.php` file.
|
|
|
|
To access the debug dashboard, you can visit the dashboard URL of your Laravel project in the browser
|
|
Since your WebSocket server has support for multiple apps, you can select which app you want to connect to and inspect.
|
|
|
|
By pressing the "Connect" button, you can establish the WebSocket connection and see all events taking place on your WebSocket server from there on in real-time.
|
|
|
|
**Note:** Be sure to set the ``APP_URL`` env variable to match the current URL where your project is running to be sure the stats graph works properly.
|
|
|
|
## Protecting the Dashboard
|
|
|
|
By default, access to the WebSocket dashboard is only allowed while your application environment is set to `local`.
|
|
|
|
However, you can change this behavior by overriding the Laravel Gate being used. A good place for this is the `AuthServiceProvider` that ships with Laravel.
|
|
|
|
```php
|
|
public function boot()
|
|
{
|
|
$this->registerPolicies();
|
|
|
|
Gate::define('viewWebSocketsDashboard', function ($user = null) {
|
|
return in_array($user->email, [
|
|
//
|
|
]);
|
|
});
|
|
}
|
|
```
|
|
|
|
## Statistics
|
|
|
|
This package allows you to record key metrics of your WebSocket server. The WebSocket server will store a snapshot of the current number of peak connections, the amount of received WebSocket messages and the amount of received API messages defined in a fixed interval. The default setting is to store a snapshot every 60 seconds.
|
|
|
|
In addition to simply storing the statistic information in your database, you can also see the statistics as they happen in real-time on the debug dashboard.
|
|
|
|

|
|
|
|
You can modify this interval by changing the `interval_in_seconds` setting in your config file.
|
|
|
|
## Cleanup old Statistics
|
|
|
|
After using the WebSocket server for a while you will have recorded a lot of statistical data that you might no longer need. This package provides an artisan command `websockets:clean` to clean these statistic log entries.
|
|
|
|
Running this command will result in the deletion of all recorded statistics that are older than the number of days specified in the `delete_statistics_older_than_days` setting of the config file.
|
|
|
|
You can leverage Laravel's scheduler to run the clean up command now and then.
|
|
|
|
```php
|
|
//app/Console/Kernel.php
|
|
|
|
protected function schedule(Schedule $schedule)
|
|
{
|
|
$schedule->command('websockets:clean')->daily();
|
|
}
|
|
```
|
|
|
|
## Disable Statistics
|
|
|
|
Each app contains an `enable_statistics` that defines wether that app generates statistics or not. The statistics are being stored for the `interval_in_seconds` seconds and then they are inserted in the database.
|
|
|
|
However, to disable it entirely and void any incoming statistic, you can uncomment the following line in the config:
|
|
|
|
```php
|
|
/*
|
|
|--------------------------------------------------------------------------
|
|
| Statistics Logger Handler
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| The Statistics Logger will, by default, handle the incoming statistics,
|
|
| store them into an array and then store them into the database
|
|
| on each interval.
|
|
|
|
|
| You can opt-in to avoid any statistics storage by setting the logger
|
|
| to the built-in NullLogger.
|
|
|
|
|
*/
|
|
|
|
// 'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger::class,
|
|
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger::class, // use the `NullStatisticsLogger` instead
|
|
```
|
|
|
|
## Custom Statistics Drivers
|
|
|
|
By default, the package comes with a few drivers like the Database driver which stores the data into the database.
|
|
|
|
You should add your custom drivers under the `statistics` key in `websockets.php` and create a driver class that implements the `\BeyondCode\LaravelWebSockets\Statistics\Drivers\StatisticsDriver` interface.
|
|
|
|
Take a quick look at the `\BeyondCode\LaravelWebSockets\Statistics\Drivers\DatabaseDriver` driver to see how to perform your integration.
|
|
|
|
## Event Creator
|
|
|
|
The dashboard also comes with an easy-to-use event creator, that lets you manually send events to your channels.
|
|
|
|
Simply enter the channel, the event name and provide a valid JSON payload to send it to all connected clients in the given channel.
|