PHP code example of ensi / laravel-metrics
1. Go to this page and download the library: Download ensi/laravel-metrics library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ensi / laravel-metrics example snippets
# app/Http/Kernel.php
protected $middleware = [
// ... other middlewares
\Ensi\LaravelMetrics\HttpMiddleware\HttpMetricsMiddleware::class,
];
$handlerStack = HandlerStack::create();
// Basic usage - only collects host-level metrics
$handlerStack->push(GuzzleMiddleware::middleware());
// With detailed path-level metrics
$handlerStack->push(GuzzleMiddleware::middleware('http_client', true, false));
// With histogram statistics
$handlerStack->push(GuzzleMiddleware::middleware('http_client', false, true));
// With both path metrics and statistics
$handlerStack->push(GuzzleMiddleware::middleware('http_client', true, true));
$client = new Client(['handler' => $handlerStack]);
$response1 = $client->get('http://httpbin.org/get');
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],
],
],
'http_client_path_stats_buckets' => [0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10],
'watch_queues' => [
'default',
],
];
bash
php artisan vendor:publish --provider="Ensi\LaravelMetrics\MetricsServiceProvider"