PHPackages                             zlodes/prometheus-client - 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. zlodes/prometheus-client

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

zlodes/prometheus-client
========================

The Prometheus Metrics client for PHP

2.3.0(3mo ago)1946.4k—3%31MITPHPPHP ^8.2CI passing

Since May 7Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/zlodes/php-prometheus-client)[ Packagist](https://packagist.org/packages/zlodes/prometheus-client)[ RSS](/packages/zlodes-prometheus-client/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (33)Versions (38)Used By (1)

PHP Prometheus Client
=====================

[](#php-prometheus-client)

[![codecov](https://camo.githubusercontent.com/95332109fe337ca7718a68051d1363a244f92f490462fa2e2839e4378da8d065/68747470733a2f2f636f6465636f762e696f2f67682f7a6c6f6465732f7068702d70726f6d6574686575732d636c69656e742f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d524f4d513856424e3041)](https://codecov.io/gh/zlodes/php-prometheus-client)

This package provides you an ability to collect and export [Prometheus](https://prometheus.io/) metrics from any modern PHP application.

Why?
----

[](#why)

- Until now, there was no working Prometheus client for modern PHP
- Framework-agnostic
- Almost zero dependencies
- Won't break your business logic even if something is wrong with Metrics Storage
- Ready to use with static analysis tools (PHPStan, Psalm)

Adapters
--------

[](#adapters)

- For Laravel: [zlodes/prometheus-client-laravel](https://github.com/zlodes/php-prometheus-client-laravel)

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

[](#installation)

```
composer require zlodes/prometheus-client
```

Flow
----

[](#flow)

TL;DR: Read [Simple example](#simple-example).

### 1. Preparation

[](#1-preparation)

1. Set up a storage to store metrics. There are four interfaces can be implemented:
    1. [CounterStorage](./src/Storage/Contracts/CounterStorage.php)
    2. [GaugeStorage](./src/Storage/Contracts/GaugeStorage.php)
    3. [HistogramStorage](./src/Storage/Contracts/HistogramStorage.php)
    4. [SummaryStorage](./src/Storage/Contracts/SummaryStorage.php)
2. Set up a [Registry](./src/Registry/Registry.php) to register your metrics. [ArrayRegistry](./src/Registry/ArrayRegistry.php) is a default implementation.
3. Register your metrics using the Registry from step 2.

### 2. Collecting

[](#2-collecting)

1. Get a collector for your metric from a [CollectorFactory](./src/Collector/CollectorFactory.php)
2. Call metric update method (e.g. `increment` on CounterCollector)

### 3. Exporting

[](#3-exporting)

1. Create a controller to export metrics. Your controller should use [Exporter](./src/Exporter/Exporter.php). [FetcherExporter](./src/Exporter/FetcherExporter.php) is a default implementation.
2. Set up a Prometheus to scrape metrics from your application using the controller from step 1.

[![](./docs/export.png)](./docs/export.png)

Simple example
--------------

[](#simple-example)

```
