PHPackages                             prismamedia/metrics - 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. prismamedia/metrics

ActiveSymfony-bundle[Logging &amp; Monitoring](/categories/logging)

prismamedia/metrics
===================

Prometheus metrics exporter

v2.1.0(1y ago)1946.4k↓36.7%5[3 issues](https://github.com/prismamedia/metrics/issues)[1 PRs](https://github.com/prismamedia/metrics/pulls)BSD-3-ClausePHPPHP &gt;=7.4CI failing

Since May 9Pushed 1y ago3 watchersCompare

[ Source](https://github.com/prismamedia/metrics)[ Packagist](https://packagist.org/packages/prismamedia/metrics)[ RSS](/packages/prismamedia-metrics/feed)WikiDiscussions 2.x Synced 1w ago

READMEChangelog (5)Dependencies (5)Versions (7)Used By (0)

Prometheus exporter for your own metrics
========================================

[](#prometheus-exporter-for-your-own-metrics)

This package is a Symfony bundle for [exporting metrics to Prometheus](https://prometheus.io/docs/instrumenting/writing_exporters/). Create your own `MetricGenerator` services to generate values on-demand, the bundle will expose them under the `/metrics` endpoint.

*It does not provide any metric by default, you have to code your own.*

Usage
-----

[](#usage)

Require the package

```
composer require prismamedia/metrics

```

Register the bundle

```
# config/bundles.php
return [
    // ...
    PrismaMedia\Metrics\Bundle\PrismaMediaMetricsBundle::class => ['all' => true],
    // ...
];
```

Import routing file

```
# config/routes.yaml
metrics:
    resource: '@PrismaMediaMetricsBundle/Resources/config/routes.xml'
```

### Implement your own metric generator

[](#implement-your-own-metric-generator)

Your metrics are generated on demand by a class implementing `PrismaMedia\Metrics\MetricGenerator` interface.

The best practice is to create a distinct classes for distinct metric names. Each class can return several values with distinct labels.

In the following example, we expose a metric named `app_article_total`labelled with each `status`. In Prometheus (&amp; Grafana), the values can be added in order to get the overall total.

```
