PHPackages                             stepovenko/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. stepovenko/laravel-prometheus

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

stepovenko/laravel-prometheus
=============================

Prometheus bridge for Laravel with Ensi-compatible facade and config

v2.0.0(today)00MITPHPPHP ^8.2

Since Jun 18Pushed todayCompare

[ Source](https://github.com/stepovenko/laravel-prometheus)[ Packagist](https://packagist.org/packages/stepovenko/laravel-prometheus)[ Docs](https://github.com/stepovenko/laravel-prometheus)[ RSS](/packages/stepovenko-laravel-prometheus/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (10)Versions (2)Used By (0)

Laravel Prometheus
==================

[](#laravel-prometheus)

[![Latest Version on Packagist](https://camo.githubusercontent.com/14f51472812fddf373f18a6530a84c0ed049dbedc76ebc65b796be48e63f2974/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737465706f76656e6b6f2f6c61726176656c2d70726f6d6574686575732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stepovenko/laravel-prometheus)[![Tests](https://github.com/stepovenko/laravel-prometheus/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/stepovenko/laravel-prometheus/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/e06cc63d18e3011400daddaa79b84071aaeb996d1fc8510e740591d5d4f45d0e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f737465706f76656e6b6f2f6c61726176656c2d70726f6d6574686575732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/stepovenko/laravel-prometheus)

Drop-in Prometheus bridge for Laravel on top of [promphp/prometheus\_client\_php](https://github.com/PromPHP/prometheus_client_php).

The package keeps the original `Ensi\LaravelPrometheus\...` namespace and the `Prometheus` facade alias, so existing application code can usually switch dependencies without mass refactoring.

Installation
------------

[](#installation)

Install the package via Composer:

```
composer require stepovenko/laravel-prometheus
```

The package declares `replace` for `ensi/laravel-prometheus`, so applications can migrate by swapping the package name in `composer.json`.

Publish the config if you want to customize bags, routes, or storage:

```
php artisan vendor:publish --tag=prometheus-config
```

Version Compatibility
---------------------

[](#version-compatibility)

PackageLaravelPHP^2.0.0^12.0 || ^13.0^8.2Notes:

- Laravel 12 installs on PHP 8.2+.
- Laravel 13 itself requires PHP 8.3+, so Composer will only resolve it on PHP 8.3+.

Basic Usage
-----------

[](#basic-usage)

The package registers the `Prometheus` facade alias automatically. If you prefer explicit imports, use `Ensi\LaravelPrometheus\Prometheus`.

Register your metrics during bootstrap:

```
use Ensi\LaravelPrometheus\Prometheus;

public function boot(): void
{
    Prometheus::counter('http_requests_count')->labels(['endpoint', 'code']);
    Prometheus::summary('http_requests_duration_seconds', 60, [0.5, 0.95, 0.99]);
}
```

Update metric values from your application code:

```
use Closure;
use Ensi\LaravelPrometheus\Prometheus;
use Illuminate\Support\Facades\Route;

public function handle($request, Closure $next)
{
    $startTime = microtime(true);
    $response = $next($request);

    Prometheus::update('http_requests_count', 1, [Route::current()?->uri, $response->status()]);
    Prometheus::update('http_requests_duration_seconds', microtime(true) - $startTime);

    return $response;
}
```

Configuration
-------------

[](#configuration)

Example `config/prometheus.php` structure:

```
return [
    'default_bag' => 'default',
    'enabled' => env('PROMETHEUS_ENABLED', true),
    'app_name' => env('PROMETHEUS_APP_NAME', env('APP_NAME')),
    'bags' => [
        'default' => [
            'namespace' => env('PROMETHEUS_NAMESPACE', 'app'),
            'route' => 'metrics',
            'basic_auth' => [
                'login' => env('PROMETHEUS_AUTH_LOGIN'),
                'password' => env('PROMETHEUS_AUTH_PASSWORD'),
            ],
            'connection' => [
                'connection' => 'default',
                'bag' => 'default',
            ],
            'label_middlewares' => [
                \Ensi\LaravelPrometheus\LabelMiddlewares\AppNameLabelMiddleware::class,
            ],
            'on_demand_metrics' => [
                \Ensi\LaravelPrometheus\OnDemandMetrics\MemoryUsageOnDemandMetric::class,
            ],
        ],
    ],
];
```

### Bags

[](#bags)

A bag is an isolated set of metrics with its own namespace, storage, middleware stack, and scrape route. This is useful when you want to separate technical metrics from business metrics.

### Supported Storages

[](#supported-storages)

- `memory`
- `apcu`
- `apcu-ng`
- `redis`
- `connection`
- `null-storage`

`ext-redis` is optional at install time and required only for `redis` and `connection` storage modes.

Advanced Usage
--------------

[](#advanced-usage)

Select another bag for metric registration and updates:

```
Prometheus::bag('business')
    ->counter('orders_count')
    ->labels(['delivery_type', 'payment_method']);

Prometheus::bag('business')
    ->update('orders_count', 1, [$order->delivery_type, $order->payment_method]);
```

### Label Middlewares

[](#label-middlewares)

Label middlewares add labels globally for a bag or locally for a metric builder chain.

```
use Ensi\LaravelPrometheus\LabelMiddlewares\LabelMiddleware;

class TenantLabelMiddleware implements LabelMiddleware
{
    public function labels(): array
    {
        return ['tenant'];
    }

    public function values(): array
    {
        return [Tenant::current()->id];
    }
}
```

Then register the middleware class in bag config:

```
'label_middlewares' => [
    \App\System\TenantLabelMiddleware::class,
],
```

### On-Demand Metrics

[](#on-demand-metrics)

On-demand metrics are refreshed right before scrape and are useful for gauges such as queue size or current memory usage.

```
use Ensi\LaravelPrometheus\MetricsBag;
use Ensi\LaravelPrometheus\OnDemandMetrics\OnDemandMetric;
use Illuminate\Support\Facades\Queue;

class QueueLengthOnDemandMetric extends OnDemandMetric
{
    public function register(MetricsBag $metricsBag): void
    {
        $metricsBag->gauge('queue_length');
    }

    public function update(MetricsBag $metricsBag): void
    {
        $metricsBag->update('queue_length', Queue::size());
    }
}
```

Development
-----------

[](#development)

```
composer install
composer test-ci
composer phpstan
```

Security
--------

[](#security)

Please review [our security policy](.github/SECURITY.md) for reporting vulnerabilities.

License
-------

[](#license)

The MIT License (MIT). See [LICENSE.md](LICENSE.md) for details.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/413b77df97d5fabf7abb91a5f5d823ebb90b53fca707a194917f4a045ba630f3?d=identicon)[Stepovenko](/maintainers/Stepovenko)

---

Top Contributors

[![MadridianFox](https://avatars.githubusercontent.com/u/3392587?v=4)](https://github.com/MadridianFox "MadridianFox (23 commits)")[![MsNatali](https://avatars.githubusercontent.com/u/8089373?v=4)](https://github.com/MsNatali "MsNatali (18 commits)")[![valerialukinykh](https://avatars.githubusercontent.com/u/123940772?v=4)](https://github.com/valerialukinykh "valerialukinykh (5 commits)")[![DimionX](https://avatars.githubusercontent.com/u/7352966?v=4)](https://github.com/DimionX "DimionX (1 commits)")[![imamberdievf](https://avatars.githubusercontent.com/u/79088728?v=4)](https://github.com/imamberdievf "imamberdievf (1 commits)")[![C0rTeZ13](https://avatars.githubusercontent.com/u/120840631?v=4)](https://github.com/C0rTeZ13 "C0rTeZ13 (1 commits)")[![wseng](https://avatars.githubusercontent.com/u/6572161?v=4)](https://github.com/wseng "wseng (1 commits)")

---

Tags

laravelMetricsprometheus

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/stepovenko-laravel-prometheus/health.svg)

```
[![Health](https://phpackages.com/badges/stepovenko-laravel-prometheus/health.svg)](https://phpackages.com/packages/stepovenko-laravel-prometheus)
```

###  Alternatives

[artprima/prometheus-metrics-bundle

Symfony 5.4/6.4/7.4/8.x Prometheus Metrics Bundle

1764.0M3](/packages/artprima-prometheus-metrics-bundle)[lkaemmerling/laravel-horizon-prometheus-exporter

A small package to gain and export long time information from Laravel &amp; Horizon for Prometheus.

1612.1M](/packages/lkaemmerling-laravel-horizon-prometheus-exporter)[leventcz/laravel-top

Real-time monitoring straight from the command line for Laravel applications.

583112.2k1](/packages/leventcz-laravel-top)[open-telemetry/opentelemetry-auto-laravel

OpenTelemetry auto-instrumentation for Laravel

582.4M8](/packages/open-telemetry-opentelemetry-auto-laravel)[renoki-co/octane-exporter

Export Laravel Octane metrics using this Prometheus exporter.

30128.9k](/packages/renoki-co-octane-exporter)[triadev/laravel-prometheus-exporter

A laravel and lumen service provider to export metrics for prometheus.

2628.6k1](/packages/triadev-laravel-prometheus-exporter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
