PHPackages                             iamfarhad/laravel-prometheus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. iamfarhad/laravel-prometheus

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

iamfarhad/laravel-prometheus
============================

Production-ready Laravel Prometheus metrics package with built-in collectors for HTTP, database, cache, queue, events, errors, filesystem, and mail monitoring

1.1.0(1mo ago)91.8k↑20.6%3MITPHPPHP ^8.1CI passing

Since Sep 10Pushed 1mo agoCompare

[ Source](https://github.com/iamfarhad/laravel-prometheus)[ Packagist](https://packagist.org/packages/iamfarhad/laravel-prometheus)[ Docs](https://github.com/iamfarhad/laravel-prometheus)[ RSS](/packages/iamfarhad-laravel-prometheus/feed)WikiDiscussions 1.x Synced 3w ago

READMEChangelog (3)Dependencies (28)Versions (5)Used By (0)

🚀 Laravel Prometheus Metrics Package
====================================

[](#-laravel-prometheus-metrics-package)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e4de3f0bb9b3df0692ab7eba0a404746a7dfb4ae5b4e06ec239c5f4e0853fe93/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f69616d6661726861642f6c61726176656c2d70726f6d6574686575732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iamfarhad/laravel-prometheus)[![Total Downloads](https://camo.githubusercontent.com/97bc785c9da278bb6978e525e238bace72941bae7f1e2b9bc951e14461aac118/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f69616d6661726861642f6c61726176656c2d70726f6d6574686575732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iamfarhad/laravel-prometheus)[![PHP Version](https://camo.githubusercontent.com/81b2ad7678e91cf4593449c2f2d4b9bb3dc8e3e44c20ad3452972411a0a31dfd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f69616d6661726861642f6c61726176656c2d70726f6d6574686575732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/iamfarhad/laravel-prometheus)[![Laravel Version](https://camo.githubusercontent.com/77df806d114ea848e08e0a6f6111533b9fa26f3c1b398dfb58383b70f2412651/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d3130253243253230313125324325323031322d7265642e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)[![GitHub Tests](https://camo.githubusercontent.com/ca2cf7955c0e2cb4f2da81c8301da712c6e8c13f0d2bdea2fc2fd961e92a46ba/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f69616d6661726861642f6c61726176656c2d70726f6d6574686575732f63692e796d6c3f6272616e63683d312e78266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/iamfarhad/laravel-prometheus/actions)

**Enterprise-grade Prometheus metrics exporter for Laravel applications with comprehensive monitoring capabilities and industry-standard SLO tracking.**

Built on the official [PromPHP/prometheus\_client\_php](https://github.com/PromPHP/prometheus_client_php) library for maximum compatibility and performance.

✨ Key Features
--------------

[](#-key-features)

- 🎯 **Complete Metric Types**: Counter, Gauge, Histogram, and Summary metrics with percentile tracking
- 📊 **Advanced Collectors**: HTTP, Database, Cache, Queue, Commands, Events, Errors, Filesystem, Mail, and Horizon
- 🏭 **Production-Ready**: Built with official PromPHP library and Laravel best practices
- 📈 **SLO Monitoring**: Industry-standard bucket configurations for p50, p95, p99, p99.9 tracking
- 💾 **Multiple Storage**: Redis, Memory, and APCu storage adapters
- 🔒 **Security First**: IP whitelisting, authentication middleware, and secure endpoint protection
- ⚡ **High Performance**: Optimized for minimal overhead with intelligent filtering
- 🧪 **Fully Tested**: Comprehensive test suite covering all components
- 📝 **Developer Friendly**: Rich documentation and intuitive API

📦 Installation
--------------

[](#-installation)

```
composer require iamfarhad/laravel-prometheus
```

### Publish Configuration

[](#publish-configuration)

```
php artisan vendor:publish --provider="Iamfarhad\Prometheus\PrometheusServiceProvider" --tag="prometheus-config"
```

### HTTP Middleware Setup

[](#http-middleware-setup)

**For HTTP request tracking, you need to register the middleware. Choose one of these simple options:**

#### ✅ **Option 1: Easy Helper (Recommended)**

[](#-option-1-easy-helper-recommended)

**No more complex setup!** Add this single line to your `bootstrap/app.php`:

```
->withMiddleware(function (Middleware $middleware) {
    // Easy one-liner for HTTP metrics - automatically checks if enabled
    \Iamfarhad\Prometheus\Support\PrometheusMiddlewareHelper::register($middleware);
})
```

**Benefits:**

- ✅ **One line setup** - No complex configuration needed
- ✅ **Automatic checks** - Only registers if HTTP collector is enabled
- ✅ **Laravel 11+ optimized** - Works perfectly with new bootstrap structure
- ✅ **Future-proof** - Handles configuration changes automatically

#### ✅ **Option 2: Manual Registration**

[](#-option-2-manual-registration)

```
->withMiddleware(function (Middleware $middleware) {
    $middleware->append(\Iamfarhad\Prometheus\Http\Middleware\PrometheusMetricsMiddleware::class);
})
```

#### ✅ **Option 3: Automatic Registration (Experimental)**

[](#-option-3-automatic-registration-experimental)

Enable automatic middleware registration in your `.env`:

```
PROMETHEUS_MIDDLEWARE_AUTO_REGISTER=true
```

**Note**: Automatic registration attempts to register middleware programmatically. If it doesn't work in your setup, use Options 1 or 2.

#### ⚡ **Option 4: Route-Specific Registration (Performance Optimized)**

[](#-option-4-route-specific-registration-performance-optimized)

For **high-performance applications** where you want to monitor only specific routes:

**Route Groups:**

```
// In routes/api.php
Route::middleware([\Iamfarhad\Prometheus\Http\Middleware\PrometheusMetricsMiddleware::class])
    ->group(function () {
        Route::get('/users', [UserController::class, 'index']);
        Route::post('/orders', [OrderController::class, 'store']);
        Route::get('/analytics/{id}', [AnalyticsController::class, 'show']);
    });
```

**Individual Routes:**

```
// Monitor only critical API endpoints
Route::get('/api/orders', [OrderController::class, 'index'])
    ->middleware(\Iamfarhad\Prometheus\Http\Middleware\PrometheusMetricsMiddleware::class);

Route::post('/api/payments', [PaymentController::class, 'process'])
    ->middleware(\Iamfarhad\Prometheus\Http\Middleware\PrometheusMetricsMiddleware::class);
```

**Route Groups with Aliases:**

```
// In bootstrap/app.php - register middleware alias
->withMiddleware(function (Middleware $middleware) {
    $middleware->alias([
        'prometheus' => \Iamfarhad\Prometheus\Http\Middleware\PrometheusMetricsMiddleware::class,
    ]);
})

// In routes/api.php - use the alias
Route::middleware(['prometheus'])->group(function () {
    Route::apiResource('users', UserController::class);
    Route::apiResource('orders', OrderController::class);
});
```

**Controller-Level Registration:**

```
