PHPackages                             rasuvaeff/yii3-metrics-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. rasuvaeff/yii3-metrics-prometheus

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

rasuvaeff/yii3-metrics-prometheus
=================================

Prometheus metrics backend for rasuvaeff/yii3-metrics (Yii3)

v1.0.2(1mo ago)04BSD-3-ClausePHPPHP 8.3 - 8.5CI passing

Since Jul 10Pushed 3w agoCompare

[ Source](https://github.com/rasuvaeff/yii3-metrics-prometheus)[ Packagist](https://packagist.org/packages/rasuvaeff/yii3-metrics-prometheus)[ Docs](https://github.com/rasuvaeff/yii3-metrics-prometheus)[ RSS](/packages/rasuvaeff-yii3-metrics-prometheus/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (32)Versions (4)Used By (0)

rasuvaeff/yii3-metrics-prometheus
=================================

[](#rasuvaeffyii3-metrics-prometheus)

[![Stable Version](https://camo.githubusercontent.com/0d749ee1407b12c9c5a10ab8137a00415dc465341ac859038e621da4f7938a43/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7261737576616566662f796969332d6d6574726963732d70726f6d6574686575732e737667)](https://packagist.org/packages/rasuvaeff/yii3-metrics-prometheus)[![Total Downloads](https://camo.githubusercontent.com/2c4b2b52d1e83e17c7572d7d95125ba6d8a9dcbc57b67e87009e1f09f157e94c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7261737576616566662f796969332d6d6574726963732d70726f6d6574686575732e737667)](https://packagist.org/packages/rasuvaeff/yii3-metrics-prometheus)[![Build](https://camo.githubusercontent.com/8ff365fda8b7b7e57ee6234bdac804710a1a0d218a7fc6a45c498b4bac982452/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7261737576616566662f796969332d6d6574726963732d70726f6d6574686575732f6275696c642e796d6c3f6272616e63683d6d6173746572)](https://github.com/rasuvaeff/yii3-metrics-prometheus/actions)[![Static Analysis](https://camo.githubusercontent.com/e6018c0f8b0bcc0cf4fba580fe4f8bdd049478e4b1c74663efa9ed2afad2a4a7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7261737576616566662f796969332d6d6574726963732d70726f6d6574686575732f7374617469632d616e616c797369732e796d6c3f6272616e63683d6d6173746572)](https://github.com/rasuvaeff/yii3-metrics-prometheus/actions)[![Psalm Level](https://camo.githubusercontent.com/d8d5b57077746d83bfde61c231163335addf1a53408f0d681b78bc23716c0d70/68747470733a2f2f73686570686572642e6465762f6769746875622f7261737576616566662f796969332d6d6574726963732d70726f6d6574686575732f6c6576656c2e737667)](https://shepherd.dev/github/rasuvaeff/yii3-metrics-prometheus)[![PHP](https://camo.githubusercontent.com/108490d697b69e1804be248b366e914b42e05c9ddcdfaa00fd640e1044b56261/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f7261737576616566662f796969332d6d6574726963732d70726f6d6574686575732f706870)](https://packagist.org/packages/rasuvaeff/yii3-metrics-prometheus)[![License](https://camo.githubusercontent.com/5516ef4bd18ba63d1e9e367dc63742cbb8e7572fdd8bfbb6476c9ba4cc520ef7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7261737576616566662f796969332d6d6574726963732d70726f6d6574686575732e737667)](https://github.com/rasuvaeff/yii3-metrics-prometheus/blob/master/LICENSE.md)[Русская версия](README.ru.md)

Prometheus backend for [`rasuvaeff/yii3-metrics`](https://github.com/rasuvaeff/yii3-metrics). It records the core `MetricRegistry` metrics into `promphp/prometheus_client_php`and exposes them at a `/metrics` endpoint.

> Using an AI coding assistant? [llms.txt](llms.txt) has a compact API reference you can pass as context.

Requirements
------------

[](#requirements)

- PHP 8.3+
- `rasuvaeff/yii3-metrics` ^1.0
- `promphp/prometheus_client_php` ^2.0
- A shared storage backend for php-fpm: `ext-apcu`, `ext-redis`, `predis/predis`, or a PDO DSN

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

[](#installation)

```
composer require rasuvaeff/yii3-metrics-prometheus
```

Installing this package binds the swappable `MeterProviderInterface` — the core `MetricRegistry` now records into Prometheus. Do **not** also bind the provider yourself (a deliberate `yiisoft/config` `Duplicate key`).

Usage
-----

[](#usage)

### Multiprocess storage (required for php-fpm)

[](#multiprocess-storage-required-for-php-fpm)

`promphp`'s default `InMemory` storage is **per process**, so under php-fpm `/metrics` would only reflect the worker that served the scrape. Use a shared adapter via env:

Runtime`PROMETHEUS_STORAGE`Needsphp-fpm (multiple workers)`apcng` (recommended), `apcu`, `redis`, `predis`, or `pdo``ext-apcu` / `ext-redis` / `predis/predis` / a PDO DSNRoadRunner / Swoole (one long-running process)`in_memory`—CLI / tests`in_memory`—`apcng` is promphp's newer APCu adapter with much cheaper scrape-time collection on large registries — prefer it over `apcu` for new deployments. `predis` uses the pure-PHP client (no `ext-redis`).

```
use Rasuvaeff\Yii3MetricsPrometheus\StorageFactory;

$adapter = (new StorageFactory())->create('apcng');
// pure-PHP Redis client (no ext-redis):
$adapter = (new StorageFactory())->create('predis', ['host' => 'redis', 'port' => 6379]);
// or, without apcu/redis (MySQL, PostgreSQL, SQLite):
$adapter = (new StorageFactory())->create('pdo', [
    'dsn' => 'mysql:host=db;dbname=app',
    'username' => 'app',
    'password' => getenv('DB_PASSWORD'),
]);
```

An unknown adapter name throws (no silent fallback), and selecting `in_memory`under php-fpm raises an `E_USER_WARNING` — a scrape that silently shows one worker's counters is worse than a visible warning.

### The `/metrics` endpoint

[](#the-metrics-endpoint)

`MetricsEndpoint` (PSR-15) renders the registry as Prometheus text exposition (`text/plain; version=0.0.4`). Route your `/metrics` path to it — it needs a PSR-17 `ResponseFactoryInterface`.

```
use Rasuvaeff\Yii3MetricsPrometheus\MetricsEndpoint;

$endpoint = new MetricsEndpoint($collectorRegistry, $responseFactory);
```

### Safe labels (cardinality)

[](#safe-labels-cardinality)

`SanitizingRouteResolver` collapses id-like path segments (`/users/123` → `/users/:id`, UUIDs → `:uuid`) for the RED middleware's `route` label. It is **opt-in** — the core binds the default `PathRouteResolver`, so rebind it in your app config (an app-layer override):

```
// config/common/di.php
use Rasuvaeff\Yii3Metrics\RouteResolverInterface;
use Rasuvaeff\Yii3MetricsPrometheus\SanitizingRouteResolver;

return [
    RouteResolverInterface::class => SanitizingRouteResolver::class,
];
```

Keep label values low-cardinality — one time series is created per unique label combination.

Recording with a label name that was **not declared** at registration throws `InvalidArgumentException` (a typo'd label would otherwise silently record under an empty value); a declared-but-missing label renders as an empty string.

### Metric namespace

[](#metric-namespace)

Set `PROMETHEUS_NAMESPACE` (params `namespace`) to prefix every metric: `checkout_http_server_requests_total`. Empty by default.

### Classes

[](#classes)

ClassPurpose`PrometheusMeterProvider`core `MeterProviderInterface` over a promphp `CollectorRegistry``PrometheusMeter` / `PrometheusCounter` / `PrometheusGauge` / `PrometheusUpDownCounter` / `PrometheusHistogram`adapters`PrometheusRenderer`render a registry as text exposition`MetricsEndpoint`PSR-15 `/metrics` handler`StorageFactory`build the storage adapter (`in_memory`/`apcu`/`apcng`/`redis`/`predis`/`pdo`)`SanitizingRouteResolver`opt-in low-cardinality route labelSecurity
--------

[](#security)

- Label values are arbitrary — keep ids/tokens out of them; use `SanitizingRouteResolver` for the route label.
- `php_info` and other promphp default metrics are disabled (`registerDefaultMetrics: false`).
- **Protect `/metrics`**: the exposition reveals routes, traffic, and error rates. Restrict it to your scrape network (firewall / ingress allowlist) or put basic auth in front — do not expose it publicly.

Examples
--------

[](#examples)

Runnable, server-independent scripts in [`examples/`](examples/). See [`examples/README.md`](examples/README.md).

### Dependency analysers

[](#dependency-analysers)

This leaf package is selected by the root application through config-plugin and may legitimately have no class reference in an autoloaded source directory. Keep the direct dependency: the application, not a core package, selects the backend or bridge. Scope the Composer Dependency Analyser exception to this package:

```
use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;
use ShipMonk\ComposerDependencyAnalyser\Config\ErrorType;

return (new Configuration())->ignoreErrorsOnPackage(
    'rasuvaeff/yii3-metrics-prometheus',
    [ErrorType::UNUSED_DEPENDENCY],
);
```

`composer-require-checker` detects used but undeclared symbols, not unused packages, so this config-only dependency needs no require-checker suppression.

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

[](#development)

The core is resolved via a path repository, so run Docker with the **monorepo root** mounted as `/repo`:

```
docker run --rm -v /path/to/monorepo:/repo -w /repo/yii3-metrics-prometheus \
  composer:2 composer build
```

See [AGENTS.md](AGENTS.md).

License
-------

[](#license)

BSD-3-Clause. See [LICENSE.md](LICENSE.md).

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance95

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 76.2% 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 ~7 days

Total

3

Last Release

33d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0812d5572a7041dfe36e222d295b2e6dc55833a605350fcde58a51a5965ed30?d=identicon)[rasuvaeff](/maintainers/rasuvaeff)

---

Top Contributors

[![rasuvaeff](https://avatars.githubusercontent.com/u/1352718?v=4)](https://github.com/rasuvaeff "rasuvaeff (16 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")

---

Tags

metricsmonitoringobservabilityphpprometheuspsr-15yii3Metricsbackendobservabilityyii3prometheus

###  Code Quality

Static AnalysisPsalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rasuvaeff-yii3-metrics-prometheus/health.svg)

```
[![Health](https://phpackages.com/badges/rasuvaeff-yii3-metrics-prometheus/health.svg)](https://phpackages.com/packages/rasuvaeff-yii3-metrics-prometheus)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B4.5k](/packages/guzzlehttp-psr7)[cakephp/cakephp

The CakePHP framework

8.9k20.0M1.9k](/packages/cakephp-cakephp)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[tempest/framework

The PHP framework that gets out of your way.

2.3k37.6k21](/packages/tempest-framework)[typo3/cms-core

TYPO3 CMS Core

3313.6M5.7k](/packages/typo3-cms-core)[flow-php/flow

PHP ETL - Extract Transform Load - Data processing framework

86337.5k](/packages/flow-php-flow)

PHPackages © 2026

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