1. Go to this page and download the library: Download ez-php/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/ */
use EzPhp\Metrics\MetricsRegistry;
use EzPhp\Metrics\RequestMetricsMiddleware;
use EzPhp\Routing\Router;
// in a service provider's register()
$this->app->bind(RequestMetricsMiddleware::class, fn ($app) => new RequestMetricsMiddleware(
$app->make(MetricsRegistry::class),
static fn (): ?string => $app->make(Router::class)->matchedRoute()?->getPath(),
));
// bootstrap
$app->middleware(RequestMetricsMiddleware::class);
// config/metrics.php
return [
'endpoint' => false, // or METRICS_ENDPOINT= (empty)
];
// routes/web.php
use EzPhp\Metrics\MetricsController;
$router->get('/metrics', [MetricsController::class, '__invoke'])
->middleware(App\Middleware\MetricsAuthMiddleware::class);
use EzPhp\Metrics\HealthMetricsListener;
$listener = new HealthMetricsListener($healthRegistry, $metricsRegistry);
$listener->record(); // before serving /metrics, or on a schedule — your call
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.