Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

prometheus-metrics-bundle

> 云原生
Open source

Symfony 5/6/7/8 Prometheus Metrics Bundle

177 stars0 likes6 views
WebsiteGitHub

About

Symfony 5/6/7/8 Prometheus Metrics Bundle

Master
Build Status
Build Status
Build Status
Coverage Status

Symfony 5.4/6.4/7.4/8.x Prometheus Metrics Bundle

A Symfony bundle for the promphp/prometheus_client_php.

Supported Versions

The bundle is currently maintained against these versions:

  • PHP: 8.2, 8.3, 8.4, 8.5
  • Symfony: 5.4, 6.4, 7.4, 8.x

Compatibility policy:

  • Symfony 5.4 is kept for legacy/LTS compatibility.
  • Symfony 8.x requires PHP 8.4 or newer.
  • CI covers the supported boundaries instead of testing the full Cartesian product of every PHP/Symfony combination.

Installation

Applications that use Symfony Flex

Open a command console, enter your project directory and execute:

bash
composer require artprima/prometheus-metrics-bundle

Applications that don't use Symfony Flex

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

bash
composer require artprima/prometheus-metrics-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

php
/metrics/prometheus.

Custom Metrics Collector
========================

If you want to collect your own metrics, you should create a class that will implement one or several interfaces that are
the children of the `Artprima\PrometheusMetricsBundle\Metrics\MetricsCollectorInterface`.

```php
namespace = $namespace;
        $this->collectionRegistry = $collectionRegistry;
    }

    private function incRequestsTotal(?string $method = null, ?string $route = null): void
    {
        $counter = $this->collectionRegistry->getOrRegisterCounter(
            $this->namespace,
            'http_requests_total',
            'total request count',
            ['action']
        );

        $counter->inc(['all']);

        if (null !== $method && null !== $route) {
            $counter->inc([sprintf('%s-%s', $method, $route)]);
        }
    }

    private function incResponsesTotal(?string $method = null, ?string $route = null): void
    {
        $counter = $this->collectionRegistry->getOrRegisterCounter(
            $this->namespace,
            'http_responses_total',
            'total response count',
            ['action']
        );
        $counter->inc(['all']);

        if (null !== $method && null !== $route) {
            $counter->inc([sprintf('%s-%s', $method, $route)]);
        }
    }

    // called on the `kernel.request` event
    public function collectRequest(RequestEvent $event): void
    {
        $request = $event->getRequest();
        $requestMethod = $request->getMethod();
        $requestRoute = $request->attributes->get('_route');

        // do not track "OPTIONS" requests
        if ('OPTIONS' === $requestMethod) {
            return;
        }

        $this->incRequestsTotal($requestMethod, $requestRoute);
    }

    // called on the `kernel.response` event
    public function collectResponse(ResponseEvent $event): void
    {
        $response = $event->getResponse();
        $request = $event->getRequest();

        $requestMethod = $request->getMethod();
        $requestRoute = $request->attributes->get('_route');

        $this->incResponsesTotal($requestMethod, $requestRoute);
    }
}

…

yaml
    App\Metrics\MyMetricsCollector:
        tags:
            - { name: prometheus_metrics_bundle.metrics_collector }

Custom Storage Adapter Factory

A storage adapter is an instance of Prometheus\Storage\Adapter. To create your own storage adapter you should create a custom factory implementing Artprima\PrometheusMetricsBundle\StorageFactory\StorageFactoryInterface.

php
getRequest();
        $request->attributes->set('_color', 'red');
    }

    public static function getSubscribedEvents(): array
    {
        return [
            KernelEvents::REQUEST => 'onKernelRequest',
        ];
    }
}

Requests will be tracked with the color label:

http_2xx_responses_total{action="GET-app_dummy_homepage",color="red"}
http_2xx_responses_total{action="GET-all",color=""}

Default Metrics

These are default metrics exported by the application:

# TYPE php_info gauge
php_info{version="7.3.25-1+ubuntu18.04.1+deb.sury.org+1"} 1
# HELP symfony_http_2xx_responses_total total 2xx response count
# TYPE symfony_http_2xx_responses_total counter
symfony_http_2xx_responses_total{action="GET-app_dummy_homepage"} 1
symfony_http_2xx_responses_total{action="all"} 1
# HELP symfony_http_requests_total total request count
# TYPE symfony_http_requests_total counter
symfony_http_requests_total{action="GET-app_dummy_homepage"} 1
symfony_http_requests_total{action="all"} 1
# HELP symfony_instance_name app instance name
# TYPE symfony_instance_name gauge
symfony_instance_name{instance="dev"} 1

…

yaml
    App\Metrics\MyMetricInfoResolver:
        tags:
            - { name: prometheus_metrics_bundle.metric_info_resolver }

Clear Metrics

The bundle provides a console command to clear metrics from the storage. Simply run:

bash
./bin/console artprima:prometheus:metrics:clear

Grafana Dashboards

Example Grafana dashboards are provided in the grafana/ directory to help you visualize the metrics exposed by this bundle.

Available Dashboards

  1. symfony-app-overview.json - Comprehensive application overview dashboard featuring:

    • HTTP request rate and response status code distribution
    • Response time percentiles and performance metrics
    • Exception monitoring by class
    • Application instance and version information
  2. symfony-app-monitoring.json - Focused monitoring dashboard with:

    • Key performance indicators (KPIs) at a glance
    • Error rate tracking and alerting
    • System health status overview
    • Instance and PHP version information

Screenshots

See how the dashboards look with real data:

Symfony Application Overview Dashboard

Symfony Application Monitoring Dashboard

For more details about the screenshots and dashboard features, see the screenshots documentation.

Usage

  1. Import the JSON files into your Grafana instance via the dashboard import feature
  2. Configure your Prometheus data source to scrape metrics from your application's /metrics/prometheus endpoint
  3. Customize the namespace template variable to match your bundle configuration (default: symfony)
  4. Select the appropriate job to filter metrics by your application instances

These dashboards are designed to work with the default metrics provided by the bundle and can be customized further based on your specific monitoring needs.

Verification

The dashboards have been validated and tested with a working demo environment. See the demo/ directory for:

  • Validation scripts that verify dashboard structure and metric references
  • Complete Docker-based demo stack with Symfony app, Prometheus, and Grafana
  • Test scripts that demonstrate actual metrics generation
  • Comprehensive verification documentation

Run php demo/validate-dashboards.php to validate the dashboard configurations.

Automated Integration Testing

This repository includes a GitHub Actions workflow that automatically:

  • Sets up a complete integration environment with Symfony app, Prometheus, and Grafana
  • Generates realistic test traffic to populate metrics
  • Captures live screenshots of the Grafana dashboards with real data
  • Makes the screenshots available as downloadable workflow artifacts

The integration workflow runs automatically on changes to the dashboard files and can also be triggered manually. You can download the latest dashboard screenshots from the GitHub Actions artifacts.

Contributors

denisvmedia Johnmeurt rmbl InboxViktorV jb-reynaud luca-nardelli
alshenetsky edditor marein ctrl-f5 ns3777k scrutinizer-auto-fixer
Yozhef karolmalinowski

Code license

You are free to use the code in this repository under the terms of the MIT license. LICENSE contains a copy of this license.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPmetricsprometheussymfonysymfony-bundle

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category云原生
PricingOpen source

> Related tools

K
Kubernetes
容器编排事实标准
H
Helm
Kubernetes 包管理器
S
seaweedfs
SeaweedFS is a distributed storage system for object storage (S3), file systems, and Iceberg tables,