Framework-agnostic Laravel middleware for Prometheus metrics collection
click/laravel-prometheus-metrics is a Laravel package for framework-agnostic laravel middleware for prometheus metrics collection.
It currently has 3 GitHub stars and 580 downloads on Packagist (latest version 1.0.1).
Install it with composer require click/laravel-prometheus-metrics.
Discover more Laravel packages by click
or browse all Laravel packages to compare alternatives.
Last updated
A simple and extensible Laravel package for collecting and exposing metrics in the Prometheus format. Ideal as a starting point for building custom monitoring solutions.
/metrics endpoint for Prometheus scrapingcomposer require click/laravel-prometheus-metrics
Publish the configuration file using Artisan:
php artisan vendor:publish --tag=prometheus-config
| Option | Description | Default |
|----------------|-----------------------------------------------------------------------------|------------------------|
| route_path | The path to expose metrics | /metrics |
| cache_ttl | Cache duration in seconds (uses Laravel Cache) | 3600 (1 hour) |
| prefix | Metric name prefix (can be set via PREFIX_PROMETHEUS_METRICS env var) | '' |
| buckets | Histogram buckets for measuring durations | [0.01, 0.05, 0.1, 0.3, 0.5, 1] |
After installation, the following route becomes available automatically:
GET /metrics
This route exposes metrics in Prometheus text exposition format.
You can attach Prometheus metric collection to specific routes via middleware.
Register the alias in your config/app.php:
'aliases' => [
'prometheus' => \YourVendor\Prometheus\Middleware\PrometheusMiddleware::class,
// ...
],
Then apply the middleware by alias:
use Illuminate\Support\Facades\Route;
Route::get('/health', fn() => ['ok' => true])
->middleware('prometheus');
use YourVendor\Prometheus\Middleware\PrometheusMiddleware;
Route::get('/health', fn() => ['ok' => true])
->middleware([PrometheusMiddleware::class]);