This is package that adds API usage cards and recorders for Laravel Pulse.
You can install the package via composer:
composer require kodamity/laravel-api-usage-pulse
Add recorders configuration inside config/pulse.php
. (If you don't have this file make sure you have published the config file of Laravel Pulse using php artisan vendor:publish --tag=pulse-config
)
Requests Statistics recorder records the number of requests and the number of successful requests in general for all users. And it records the number of requests and the number of successful requests for each user.
return [
// ...
'recorders' => [
// Existing recorders...
\Kodamity\Libraries\ApiUsagePulse\Recorders\RequestsStatistics::class => [
'enabled' => env('PULSE_KDM_API_USAGE_REQUESTS_STATISTICS_ENABLED', true),
'sample_rate' => env('PULSE_KDM_API_USAGE_REQUESTS_STATISTICS_SAMPLE_RATE', 1),
'ignore' => [
'#^/pulse$#', // Pulse dashboard...
],
],
],
];
Responses Statistics recorder records the average response time and the number of responses by status code group for all users.
return [
// ...
'recorders' => [
// Existing recorders...
\Kodamity\Libraries\ApiUsagePulse\Recorders\ResponsesStatistics::class => [
'enabled' => env('PULSE_KDM_API_USAGE_RESPONSES_STATISTICS_ENABLED', true),
'sample_rate' => env('PULSE_KDM_API_USAGE_RESPONSES_STATISTICS_SAMPLE_RATE', 1),
'ignore' => [
'#^/pulse$#', // Pulse dashboard...
],
'records' => [
\Kodamity\Libraries\ApiUsagePulse\Enums\ResponseStatusGroup::Informational->value,
\Kodamity\Libraries\ApiUsagePulse\Enums\ResponseStatusGroup::Successful->value,
\Kodamity\Libraries\ApiUsagePulse\Enums\ResponseStatusGroup::Redirection->value,
\Kodamity\Libraries\ApiUsagePulse\Enums\ResponseStatusGroup::ClientError->value,
\Kodamity\Libraries\ApiUsagePulse\Enums\ResponseStatusGroup::ServerError->value,
],
],
],
];
To add the card to the Pulse dashboard, you must first publish the vendor view.
php artisan vendor:publish --tag=pulse-dashboard
Then, you can modify the dashboard.blade.php
file and add the card to the dashboard.
<livewire:kodamity.pulse.api-usage.requests-summary cols="5" rows="2" />
<livewire:kodamity.pulse.api-usage.response-statuses-graph cols="7" />
<livewire:kodamity.pulse.api-usage.response-times-graph cols="7" />
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.