ensi / laravel-metrics
laravel metrics
Installs: 37 114
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: ^8.1
- ensi/laravel-prometheus: ^1.0.10
- guzzlehttp/guzzle: ^7.0
- psr/http-message: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.2
- nunomaduro/collision: ^6.0 || ^7.0 || ^8.1
- orchestra/testbench: ^7.0 || ^8.0 || ^9.0
- pestphp/pest: ^1.22 || ^2.0
- pestphp/pest-plugin-laravel: ^1.1 || ^2.0
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.11
- spaze/phpstan-disallowed-calls: ^2.15
This package is auto-updated.
Last update: 2024-12-06 08:51:07 UTC
README
The package adds general-purpose metrics for a laravel web application. It is an addition toensi/laravel-prometheus
Installation
You can install the package via composer:
composer require ensi/laravel-metrics
Publish the config with:
php artisan vendor:publish --provider="Ensi\LaravelMetrics\MetricsServiceProvider"
Basic Usage
Add Http Middleware
# app/Http/Kernel.php protected $middleware = [ // ... other middlewares \Ensi\LaravelMetrics\HttpMiddleware\HttpMetricsMiddleware::class, ];
Add Guzzle Middleware to your http clients
$handlerStack = HandlerStack::create(); $handlerStack->push(GuzzleMiddleware::middleware()); $client = new Client(['handler' => $handlerStack]); $response1 = $client->get('http://httpbin.org/get');
Configuration
The structure of the configuration file
return [ 'ignore_commands' => [ 'kafka:consume', ], 'ignore_routes' => [ 'prometheus.*' ], 'http_requests_stats_groups' => [ '<stats-group-name>' => [ // If your app runs in multiple containers and each of them is responsible for its own metrics, // then you don't need to use the "summary" 'type' => 'summary', 'route_names' => ['*'], // or use prefix, like ['catalog.*', 'profile.favorites'], 'time_window' => 30, 'quantiles' => [0.5, 0.75, ,0.95], ], '<stats-group-name>' => [ 'type' => 'histogram', 'route_names' => ['*'], // or use prefix, like ['catalog.*', 'profile.favorites'], 'buckets' => [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10], ], ] ];
ignore_routes - a list of names of routes for which you do not need to track the processing time of http requests.
ignore_commands - a list of team names for which you do not need to track metrics.
http_requests_stats_groups - a list of histograms and percentiles. Each stats group has a list of the names of the routes that it tracks.
Thus, you can count statistics not for the entire application, but for individual groups of endpoints.
Metrics
The names of the metrics are presented without the namespace.
Contributing
Please see CONTRIBUTING for details.
Testing
- composer install
- composer test
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
License
The MIT License (MIT). Please see License File for more information.