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

ActiveLibrary

ensi/laravel-prometheus
=======================

laravel prometheus

1.1.0(2mo ago)283.7k↓27.1%3[2 PRs](https://github.com/ensi-platform/laravel-prometheus/pulls)1MITPHPPHP ^8.1CI passing

Since Nov 25Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/ensi-platform/laravel-prometheus)[ Packagist](https://packagist.org/packages/ensi/laravel-prometheus)[ RSS](/packages/ensi-laravel-prometheus/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (20)Versions (20)Used By (1)

Prometheus client for laravel
=============================

[](#prometheus-client-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f633ff895f8a4020ee7f4e76037913b900e66ad8df8c2a13d09d94f2203c6303/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656e73692f6c61726176656c2d70726f6d6574686575732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ensi/laravel-prometheus)[![Tests](https://github.com/ensi-platform/laravel-prometheus/actions/workflows/run-tests.yml/badge.svg?branch=master)](https://github.com/ensi-platform/laravel-prometheus/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/4c355b97d36f879060b1707830297c704a60abe9dc158c552d5efe886820ebed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656e73692f6c61726176656c2d70726f6d6574686575732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ensi/laravel-prometheus)

Adapter for [promphp/prometheus\_client\_php](https://github.com/PromPHP/prometheus_client_php)

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

[](#installation)

You can install the package via composer:

```
composer require ensi/laravel-prometheus
```

Publish the config with:

```
php artisan vendor:publish --provider="Ensi\LaravelPrometheus\PrometheusServiceProvider"
```

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

[](#version-compatibility)

Laravel PrometheusLaravelPHP^1.0.0^9.x^8.1^1.0.4^9.x || ^10.x^8.1^1.0.9^9.x || ^10.x || ^11.x^8.1^1.1.0^9.x || ^10.x || ^11.x || ^12.x^8.1Basic Usage
-----------

[](#basic-usage)

Before you wind up the metric counters, you need to register them. The best thing to do is to use the boot() method from the application service provider.

```
# app/Providers/AppServiceProvider.php
public function boot() {
    Prometheus::counter('http_requests_count')->labels(['endpoint', 'code']);
    Prometheus::summary('http_requests_duration_seconds', 60, [0.5, 0.95, 0.99]);
}
```

Updating the counter value is just as easy

```
# app/Http/Middleware/Telemetry.php
public function handle($request, Closure $next)
{
    $startTime = microtime(true);
    $response = $next($request);
    $endTime = microtime(true);

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

    return $response;
}
```

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

[](#configuration)

The structure of the configuration file

```
# config/prometheus.php
return [
    'default_bag' => '',
    'enabled' => env('PROMETHEUS_ENABLED', true),
    'app_name' => env('PROMETHEUS_APP_NAME', env('APP_NAME')),
    'bags' => [
        '' => [
            'namespace' => '',
            'route' => '',
            'basic_auth' => [
                'login' => env('PROMETHEUS_AUTH_LOGIN'),
                'password' => env('PROMETHEUS_AUTH_PASSWORD'),
            ],
            '' => [
                ''
            ],
            'label_middlewares' => [
                ''
            ],
            'on_demand_metrics' => [
                ''
            ]
        ],
    ],
];
```

**Bag**

You may want to have several sets of metrics, for example, one set with technical metrics, such as the number of http requests or unexpected exceptions, and a second set for business values, such as the number of orders or impressions of a particular page. To do this, the concept of bag is introduced. You can configure several bugs by specifying your own data warehouse for each, a separate endpoint for collecting metrics, etc.

**Storage type**

You can use all the storage (Adapters) from the promphp/prometheus\_client\_php package. In addition, you can specify the name of the redis connection from the file `config/databases.php`.

Storage configuration options.
Store metrics in the process memory.

```
'memory' => true
```

Use apcupsd

```
'apcu' => [
    'prefix' => 'metrics'
]
```

or an alternative APCuNG adapter

```
'apcu-ng' => [
    'prefix' => 'metrics'
]
```

A Redis adapter that will create a phpredis connection by itself

```
'redis' => [
    'host' => '127.0.0.1',
    'port' => 6379,
    'timeout' => 0.1,
    'read_timeout' => '10',
    'persistent_connections' => false,
    'password' => null,
    'prefix' => 'my-app',
    'bag' => 'my-metrics-bag'
]
```

Laravel Redis connection from `config/databases.php`. The same Redis adapter will be created under the hood, but it will take the native phpredis connection object from laravel's Redismanager.

```
'connection' => [
    'connection' => 'default',
    'bag' => 'default',
]
```

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

[](#advanced-usage)

You can select another bag to create and update metrics in it using the `bag($bagName)` method.

```
# app/Providers/AppServiceProvider.php
public function boot() {
    // создаём метрики в конкретном bag
    Prometheus::bag('business')->counter('orders_count')->labels(['delivery_type', 'payment_method'])
}

# app/Actions/CreateOrder.php
public function execute(Order $order) {
    // ...
    Prometheus::bag('business')->update('orders_count', 1, [$order->delivery_type, $order->payment_method]);
}
```

### Label Middlewares

[](#label-middlewares)

You can add a label to all bagmetrics by specifying the so-called Label middleware in its configuration. Label middleware is triggered at the moment the metric is determined and at the moment its counter is updated, adding in the first case to the label name, and in the second case the value.

For example, we have a TenantLabelProvider

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

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

We register it in the bag configuration.

```
# config/prometheus.php
return [
    // ...
    'bags' => [
        'default' => [
            // ...
            'label_middlewares' => [
                \App\System\TenantLabelMiddleware::class,
            ]
        ],
    ],
];
```

Then, as usual, we work with metrics.

```
Prometheus::counter('http_requests_count')->labels(['endpoint', 'code']);
// ...
Prometheus::update('http_requests_count', 1, [Route::current()?->uri, $response->status()]);
```

As a result, the metric will have not two, but three labels

```
app_http_requests_count{endpoint="catalog/products",code="200",tenant="JBZ-987-H6"} 987

```

### On demand metrics

[](#on-demand-metrics)

Sometimes metrics are not linked to application events. Usually these are metrics of the gauge type, which it makes no sense to update on each incoming request, because prometheus will still take only the last set value. Such metrics can be calculated at the time of collection of metrics by prometheus. To do this, you need to create a so-called on demand metric. This is the class in which you register metrics and set values in them.

```
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());
    }
}
```

The update of such metrics occurs at the moment prometheus addresses the endpoint of obtaining metrics.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.

### Testing

[](#testing)

1. composer install
2. composer test

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](.github/SECURITY.md) on how to report security vulnerabilities.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

55

—

FairBetter than 98% of packages

Maintenance87

Actively maintained with recent releases

Popularity36

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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

Every ~80 days

Recently: every ~157 days

Total

16

Last Release

63d ago

Major Versions

v0.1.0 → 1.0.02022-12-10

PHP version history (2 changes)v0.1.0PHP &gt;=8.1

1.0.10PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8089373?v=4)[Наталия](/maintainers/MsNatali)[@MsNatali](https://github.com/MsNatali)

![](https://avatars.githubusercontent.com/u/7352966?v=4)[Andrey](/maintainers/dimionx)[@DimionX](https://github.com/DimionX)

---

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)")[![C0rTeZ13](https://avatars.githubusercontent.com/u/120840631?v=4)](https://github.com/C0rTeZ13 "C0rTeZ13 (1 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)")

---

Tags

laravelprometheusprometheus-client-library

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11120.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

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