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.
- Ready-to-use
/metrics
endpoint for Prometheus scraping - Flexible and centralized configuration
- Extensible architecture with support for custom collectors
- Histogram buckets for operation duration tracking
- Cache support to reduce overhead
composer 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]);