PHPackages                             phprometheus/phprometheus - 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. phprometheus/phprometheus

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

phprometheus/phprometheus
=========================

Opinionated library for shipping metrics to Prometheus.

v0.2.0(2y ago)15.7k↓100%MITPHPPHP &gt;=8.0

Since Sep 21Pushed 2y agoCompare

[ Source](https://github.com/phprometheus/phprometheus)[ Packagist](https://packagist.org/packages/phprometheus/phprometheus)[ RSS](/packages/phprometheus-phprometheus/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (5)Versions (6)Used By (0)

PHPrometheus
============

[](#phprometheus)

> A lightweight, modular, object-oriented library for exporting metrics to Prometheus.

This is the main package for PHPrometheus. This package aims to provide a higher-level interface over the [officially-sanctioned Prometheus package](https://github.com/PromPHP/prometheus_client_php), at the cost of being slightly more opinionated.

Headline features:

- Lightweight by default, additional functionality or support for specific frameworks pulled in with optional extra packages.
- Object-oriented for sensible typing, and to match the ergonomics of your application.
- Metrics are registered on the fly as they are used - no need to maintain a separate list of metrics and their labels elsewhere in your application.

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

[](#installation)

Requires PHP 8+.

```
composer require phprometheus/phprometheus
```

### Modules

[](#modules)

PHPrometheus is highly modular. This means that you might find other functionality to plug in, but you don't need to load the kitchen sink if you only need the basics.

- [phprometheus/phprometheus-push-gateway](https://github.com/phprometheus/phprometheus-push-gateway) \[wip\] - For sending metrics to a configured [Prometheus Push Gateway](https://prometheus.io/docs/practices/pushing/) so you don't need to expose a metrics endpoint. Great for queue workers, for example.
- [phprometheus/phprometheus-laravel](https://github.com/phprometheus/phprometheus-laravel) \[wip\] - For easy integration within a Laravel application. Includes a pre-configured service provider, `/metrics` endpoint, and route middleware to automatically instrument your HTTP endpoints.
- phprometheus/phprometheus-guzzle-middleware \[coming soon!\] - automatically instrument your calls to external services.
- phprometheus/phprometheus-psr15-middleware \[coming soon!\] - automatically instrument your HTTP endpoints with this handy middleware.
- phprometheus/phprometheus-container \[coming soon!\] - pre-configured PHPrometheus IoC implementation in a PSR-11 container.
- phprometheus/phprometheus-bundle \[coming, perhaps\] - Symfony support.

Usage
-----

[](#usage)

Each of your metrics is a class that subclasses a Prometheus metric type.

```
class HappyCustomer extends \Phprometheus\Counter
{
    public static function name(): string
    {
        return 'happy_customers_total';
    }

    public static function help(): string
    {
        return 'Counter of customers who like our app.';
    }
}
```

Then, elsewhere in your application:

```
/** In your service container */
$prometheus = new \Phprometheus\PrometheusExporter(
    'my_namespace',
    new \Prometheus\CollectorRegistry(
        new \Prometheus\Storage\InMemory()
    )
);

/** Then, you can inject and use it in your domain logic: */
$this->prometheus->incrementCounter(new HappyCustomer([
    'custom_label' => 'yes'
]));
```

Finally, you can export the metrics on a `/metrics` endpoint, as is the norm for Prometheus:

```
/** In a controller or similar: */
$metrics = $this->prometheus->flush();
$renderer = new RenderTextFormat();

/** Assuming Symfony HttpFoundation here, but use what you prefer */
return new Response(
    $renderer->render($metrics),
    Response::HTTP_OK,
    [ 'Content-Type' => RenderTextFormat::MIME_TYPE ]
);
```

### Metric types

[](#metric-types)

You may extend any of the following classes when creating your metrics:

- `Phprometheus\Counter::class`
- `Phprometheus\Gauge::class`
- `Phprometheus\Histogram::class`

All the above implement a common interface, `Phprometheus\Metric::class`.

Extending any of these metric types requires filling out a metric name and help string. In addition, the Histogram allows overriding its default buckets, if you desire:

```
class RequestDuration extends \Phprometheus\Histogram
{
    public static function name(): string
    {
        return 'request_duration_seconds';
    }

    public static function help(): string
    {
        return 'How long it takes to service requests.';
    }

    public static function buckets(): array
    {
        return [ 0.2, 0.3, 0.5, 0.8, 1.3 ];
    }
}
```

### Storage adapters

[](#storage-adapters)

When creating an instance of PHPrometheus, you must pass a storage adapter to it. This is because of PHP's request model, to allow persisting of metrics across requests.

```
$prometheus = new \Phprometheus\PrometheusExporter(
    'my_namespace',
    new \Prometheus\CollectorRegistry(
        new \Prometheus\Storage\InMemory()
    )
);
```

Note that in most cases (unless using the [Push Gateway](https://github.com/phprometheus/phprometheus-push-gateway)) you won't want to use the InMemory adapter, as metrics are not persisted anywhere. The following additional storage adapters are available:

- `Prometheus\Storage\APC::class`
- `Prometheus\Storage\Redis::class`

Some more info on this is available in the [PromPHP](https://github.com/PromPHP/prometheus_client_php) repository that this is built on.

### Labels

[](#labels)

Each Metric's constructor accepts an optional array of labels. These are simple key/value pairs that correspond to [Prometheus labels](https://prometheus.io/docs/concepts/data_model/).

For example, the following:

```
$metric = new HappyCustomer([ 'star_rating' => 5, 'has_paid_us_money' => true ]);

$this->prometheus->observeHistogram($metric, 2.5);
```

Would result in the following output:

```
# HELP happy_customers Counter of customers who like our app.
# TYPE happy_customers counter
happy_customers{star_rating="5", has_paid_us_money="true"} 123

```

License
-------

[](#license)

This project is released under the MIT license.

Copyright 2021 Kieran Patel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~223 days

Total

5

Last Release

750d ago

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

v0.2.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/986acba5713cdb47bd0f0e9b0e7988f3b4a2cc43f40bdcbb9820a64f79d6516d?d=identicon)[kieranajp](/maintainers/kieranajp)

---

Top Contributors

[![kieranajp](https://avatars.githubusercontent.com/u/681426?v=4)](https://github.com/kieranajp "kieranajp (18 commits)")

---

Tags

hacktoberfestmetricsprometheus

###  Code Quality

Static AnalysisPsalm

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phprometheus-phprometheus/health.svg)

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

###  Alternatives

[spatie/laravel-prometheus

Export Laravel metrics to Prometheus

2531.2M4](/packages/spatie-laravel-prometheus)[promphp/prometheus_push_gateway_php

Prometheus Push Gateway client for PHP applications.

312.2M5](/packages/promphp-prometheus-push-gateway-php)[arquivei/laravel-prometheus-exporter

A Prometheus exporter for Laravel and Lumen

18796.0k1](/packages/arquivei-laravel-prometheus-exporter)

PHPackages © 2026

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