kodamity / laravel-api-usage-pulse
API usage cards for Laravel Pulse
Fund package maintenance!
Kodamity
Requires
- php: ^8.3
- illuminate/contracts: ^10.0 || ^11.0 || ^12.0
- illuminate/http: ^10.0 || ^11.0 || ^12.0
- illuminate/support: ^10.0 || ^11.0 || ^12.0
- illuminate/view: ^10.0 || ^11.0 || ^12.0
- laravel/pulse: ^1.0
- livewire/livewire: ^3.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- ergebnis/composer-normalize: ^2.45
- friendsofphp/php-cs-fixer: ^3.67
- larastan/larastan: ^2.9 || ^3.0
- nunomaduro/collision: ^7.10.0 || ^8.1.1
- orchestra/testbench: ^8.22 || ^9.0 || ^10.0
- pestphp/pest: ^2.0 || ^3.0
- pestphp/pest-plugin-arch: ^2.0 || ^3.0
- pestphp/pest-plugin-laravel: ^2.0 || ^3.0
- phpro/grumphp: ^2.10
- phpstan/phpstan: ^1.10 || ^2.0
- phpstan/phpstan-deprecation-rules: ^1.1 || ^2.0
- phpstan/phpstan-phpunit: ^1.3 || ^2.0
README
API usage cards for Laravel Pulse
This is package that adds API usage cards and recorders for Laravel Pulse.
Installation
You can install the package via composer:
composer require kodamity/laravel-api-usage-pulse
Recorders
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
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
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, ], ], ], ];
Dashboards
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" />
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.