promphp/prometheus_client_php
Prometheus client library for PHP with Redis or APCu-based aggregation (plus in-memory adapter). Register and update counters, gauges, histograms, and summaries via CollectorRegistry, then expose metrics in Prometheus text format for scraping.
CollectorRegistry and expose metrics via HTTP routes (e.g., /metrics). The package’s stateless design (except for storage backends) avoids conflicts with Laravel’s request lifecycle.service:laravel, environment:production). This fits Laravel’s modular architecture (e.g., packages like spatie/laravel-metrics).getOrRegisterCounter()) reduce integration effort. Laravel’s service providers can initialize the registry and storage adapter on boot./metrics endpoint can be exposed via Laravel’s routing system, with authentication (e.g., basic auth, IP whitelisting) added via middleware.promphp/prometheus_push_gateway_php) be used?/metrics?scrape_interval)?CollectorRegistry and storage adapter in AppServiceProvider::boot().response_time_ms via Kernel::handle())./metrics endpoint with auth middleware.scrape_configs to target Laravel’s /metrics endpoint.laravel_)./health) with basic counters (e.g., http_requests_total).database_query_duration_seconds).job_processing_time_seconds).auth_attempts_total).spatie/laravel-metrics (if using different storage backends).predis/predis is installed for Predis support.pecl install apcu and PHP apcu.enable_cli=1 for CLI metrics.// config/app.php
'prometheus' => [
'adapter' => env('PROMETHEUS_ADAPTER', 'redis'),
'redis' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'port' => env('REDIS_PORT', 6379),
],
];
// app/Providers/AppServiceProvider.php
public function boot(): void
{
$adapter = config('prometheus.adapter');
$registry = new CollectorRegistry(
match ($adapter) {
'redis' => new Redis(),
'predis' => new Predis(),
'apcu' => new APCu(),
default => new InMemory(),
}
);
app()->singleton('prometheus.registry', fn() => $registry);
}
// routes/web.php
Route::get('/metrics', function () {
$registry = app('prometheus.registry');
$renderer = new RenderTextFormat();
header('Content-type: ' . RenderTextFormat::MIME_TYPE);
return $renderer->render($registry->getMetricFamilySamples());
})->middleware('auth:prometheus');
// Example: Track API requests
Route::middleware(['metrics'])->group(function () {
Route::get('/api/users', [UserController::class, 'index']);
});
promphp/prometheus_client_php for PHP 8.5+ compatibility and storage adapter improvements.predis/predis or php-redis if using Redis.laravel_http_requests_total) to avoid breaking Prometheus queries.relabel to standardize labels (e.g., job=laravel_app).redis-cli info memory). Set maxmemory-policy to allkeys-lru.apc.shm_size to avoid evictions.ping).APCng for CLI stability.tideways/xhprof).How can I help you explore Laravel packages today?